I have a simple workflow that has a build job, a hold (type approval), then a release job.
If I perform a checkout in the build job and the release job, will they always use the same SHA and get the same code?
Context:
I have a Clojure library I want to release to Clojars. I don’t want every commit to automatically get deployed so that is why I added the manual approval step.
I build a jar in the build job and store it as an artefact, as its nice to be able to manually download a CI built jar if required.
Originally I also persisted the jar to the workspace which I restored in the release step. I then tried to use lein deploy to push this prebuilt jar to Clojars. However lein rebuilds the jar which meant it contained no source files and was completely broken!
So my options seem to be:
try and stop lein from rebuilding the jar
persist the src to the workspace
checkout the same SHA again
If checking out code in different workflow jobs is smart enough to use the same SHA that seemed like the simplest option, but was unable to find a definitive answer, hence my question!
I imagine it would use the same hash, though I’ve not done this, so I cannot say definitively.
However, if it does not, then the hash should be available in env vars at the start of the held job.
I think the simplest approach is to build the workflow as you want it to work, and then try it (get the job into a hold state, push a dummy commit to your deployment branch, then release the hold, and see what happens).
If both of the above approaches fail, then you can always use a workspace to copy over the required hash.
Hi @halfer, thanks for the reply, I just tested this as per your suggestion.
I can confirm the CIRCLE_SHA1 was set to the correct SHA of the commit that triggered the workflow and the built in checkout step does:
git reset --hard "$CIRCLE_SHA1"
So unless I’m misunderstanding reset --hard I’d say it’s safe to checkout in multiple jobs in the same workflow, regardless of how long they are on hold or how many additional commits have been made.
Did you find that a standard checkout step was insufficient for your needs (perhaps because it would checkout the wrong hash?). I think git reset --hard would be fine too, but it is worth using the tools available if they will work.