Post-clone working directory



Our repository is structured like this:

  - various
  - files
  - .circleci/
    - config.yml
  - subfolder/
    - area where commands should be run
    - code

Which requires most steps to be written like this:

  - run:
     command: |
       cd subfolder
       actual command

Is there a way around this? I’d like to see a clone_path and a working_directory, or something like that.


From what I understand, your code will always be checked out into ~/yourprojectname/, no matter what you set as working_directory. Have you tried setting working_directory to ~/repo/subfolder?


This applies to CircleCI 1.0, and technically that can be changed as well.

1.0 has build_dir for this purpose but 2.0 doesn’t have a direct equivalent. If you want to prefix every command, you can set the “shell default” to include a cd subdirectory command.

Another method is, if you are using multiple jobs. In the first job, the repo is cloned to working_directory and this is where commands run. In additional jobs, you can then set working_directory to the subdirectory, and then that’s where the commands will run.

Also, instead of using cd, you can just run the commands from the working_directory using the relative pathname.


@FelicianoTech thanks for the reply and suggestions. I didn’t find documentation for anything like setting a shell default, but I did find that the checkout step has an option to pass in a path which defaults to the given working directory.

Unfortunately, your suggestion to run the commands using a relative pathname doesn’t work with commands which don’t take a path, but instead look at the PWD environment variable. Dependency management is the main culprit here.

In order to clean things up, I’ve changed my code to look like this:

- working_directory: ~/repo/subfolder
  - checkout:
      path: ~/repo
  - run: actual command to run in subfolder

This should work for all of our monorepo/megarepo needs.


Very nice. I actually didn’t even know checkout supports that myself. Your solution is better than mine.