CIRCLE_WORKING_DIRECTORY doesn't expand

envars

#1

The default value for CIRCLE_WORKING_DIRECTORY is ‘~/project’. This ~ char will never get a chance to be expended by a shell to /home/username. I.e.

echo $CIRCLE_WORKING_DIRECTORY outputs ~/project instead of /home/username/project.


#2

Thanks for posting. I’ll share with our engineers.


#3

Agreed, just ran into a similar issue where I assumed $CIRCLE_WORKING_DIRECTORY was expanded into an absolute path. For now I work around the problem by setting working_directory to /home/circleci/project.


#4

run: mkdir -p $CIRCLE_WORKING_DIRECTORY/foo/bar makes a directory in the current directory called ~ with a directory under that called project/foo/bar. This is very unintuitive to anyone who has used a linux shell.


#5

Hey everyone,

Last week I moved this topic to the “Bug Reports” category because clearly this is a bug. It’s reported internally and we’ll work on fixing it.

In the meantime here’s a quick fix. If you need the variable in just one step you can do:

CIRCLE_WORKING_DIRECTORY="${CIRCLE_WORKING_DIRECTORY/#\~/$HOME}"

If you need it in multiple steps, for the first step in a job you can do:

      - run:
            name: "Fix CIRCLE_WORKING_DIRECTORY"
            command: echo 'CIRCLE_WORKING_DIRECTORY="${CIRCLE_WORKING_DIRECTORY/#\~/$HOME}"' >> $BASH_ENV

#7

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.