CircleCI local debugging tips

Recently, I’ve been working with CircleCI for doing some automation and testing work, and I’ve been trying to run things locally on my machine, rather than pushing everything up to CircleCI to have it run on their servers.

But I kept running into problems with things like SSH keys, known hosts, and environment variables. These are all things that have easy solutions when you’re running them on the CircleCI servers (e.g., the add-ssh-keys special step.)

However, not so easy when you’re running the jobs locally with the command line interface.

But after quite a bit of googling for an answer, I found that it was much easier than I thought to make it work. Turns out, you can use docker-style volume syntax with the circleci CLI tools!

So, if you are running a local circleCI job called check-repo, for instance, you can mount your local ~/.ssh directory directly into the container, and viola!

circleci local execute --job check-repo --volume /home/{YourUsername}/.ssh:/root/.ssh

Likewise, you can include runtime values for environment variables you may need with the -e flag:

circleci local execute --job check-repo --volume /home/{YourUsername}/.ssh:/root/.ssh -e GITHUB_TOKEN=Y0UrG17hU870k3nG03zH3r3

Remember, when you’re mounting local folders into the container, you’re going to want to use absolute paths, not relative ones.

Was this helpful to you? Drop me a line and let me know.