Is CIRCLE_SHA1 the same in different jobs?

Hi,

I have 2 jobs (build and deploy) in one workflow, I use CIRCLE_SHA1 as the docker image tag, but will the value of “$CIRCLE_SHA1” in “deploy” job the same as “build”? What will happen if “build” is running and one user commits the code again?

Hi,

The environment variable CIRCLE_SHA1 will be the same for all builds in a pipeline because they are referencing the commit information. If you rerun jobs from the same commit, then the CIRCLE_SHA1 will be the same. You can find a list of the built-in environment variables here: https://circleci.com/docs/2.0/env-vars/#built-in-environment-variables

If a build is running and another commit is created, depending on the project configuration, the previous jobs will stop if you have the “Auto cancel redundant builds” feature enabled.

If I understand correctly (suppose we disabled auto-cancel redundant builds), we “checkout” in different jobs, if the the first job was still running and someone pushed to the repo, the second job should have the latest commit id by “checkout” step right?

Good question! When a pipeline is triggered by a commit to your repository, all workflows will be run for that commit, on that commit. Therefore, CIRCLE_SHA1 will remain the same. The checkout function resets to the CIRCLE_SHA1 commit before actually checking out to prevent the alternative case from happening. You can view the the “Checkout code” step in your workflows to see how it is configured.