CIRCLE_WORKING_DIRECTORY doesn't expand

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.

5 Likes

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

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.

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.

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
3 Likes

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