I’m trying to create a config file that follows the following pattern:
Run a command (terraform) that will either return an exit code 0 (everything is fine) or 2 (changes are needed)
If everything is fine (0 code) then the workflow is done and it can move on
If the command says that things need changing (2 code), I want circleci to run a manual approval state so that I can check things over before it proceeds.
Is this possible?
I tried to do this with steps, but it appears that manual approval is only allowed for jobs. I found the very helpful step when with condition: on_fail but I don’t know if or how it could trigger a different job to run or be skipped.
My first attempt went something like this:
- run:
name: Plan Terraform
command: |
cd ./bin
planresult=$(terraform plan)
if [[ $? != 0 ]]; then
exit 2
else
exit 0
fi
- when:
condition: on_fail
steps:
????
You should be able to do the approval job as a condition: on_fail and make the deploy job require that. I think you may want to duplicate the deploy job though, one for success, and one for after the approval job.
So, based on what you say, I could use an anchor for the two options (success and failure) so that I don’t have to duplicate things. That sounds fine, but I’m not sure how to get the approval step in there as that drops back out to the job level, and I don’t see any condition option in the workflow/job https://circleci.com/docs/2.0/configuration-reference/#jobs-1.