PWD stays the original folder even if cd 'some-other-folder'

it seems that circle ci changes the directory after every command even if I want to cd into another folder. I’ve run an experiment where I have the following commands run in my job:

  • run: pwd //resultA
  • run: ls -la // (i see the folder)
  • run: cd folder-name
  • run: pwd // I get resultA and not resultA/folder-name

If I do cd folder-name && my command i get the right folder context.

Why is this?

You are correct - every command is executed in the directory specified by the working_directory key in the definition of your job. The default value is ~/project. You can override this on each step if you wish.

  - run:
      command: pwd
      working_directory: /tmp

Marc

1 Like

As well as Marc’s approach, you can use to do everything in one command:

run: cd folder-name && pwd