I am new to CircleCI and recently created a following workflow for a CI automation:
I have 4 jobs that I want running in sequence (so every job depends on successful completion of the previous job). This is working fine for me.
Now, I want to run these jobs only if a certain condition applies (basically inspect a git command results and make a decision whether or not to run a CI job). I found 2 ways of achieving this:
using circleci step halt - the issue with this is it halts only the current job, so CircleCI return a success for that job. This causes the other jobs to run as well. But I dont want it to run any job and just terminate entirely.
other workaround is to return an exit 1 error code, so it makes the current job “fail”, so no other jobs will run which depend on the success of the current job. However, I don’t like the fact that CircleCI will show the job as failed (if a certain condition isn’t applied.
Is there any other elegant solution to achieve this?
Have you looked at the new conditional steps system in the 2.1 version of the configuration format? I wonder if your dependent jobs should just be steps, so that you don’t have to fail to stop future jobs running.
Could you send me a reference link to the new conditional steps system? I am happy to look it up. I tried clubbing them all into one single job with multiple step (instead of 4) but the problem is each of these require a different build environment (such as macos and android). To make it a bit clear, here’s a code snipper for my config file:
Is there a way I could do both of these jobs in the same environment? In that case, I can combine everything in one single shell script and encapsulate the conditionals within the scripts and handle them all in there without worrying about any of the CircleCI config shenanigans.
Thanks for the details but like I mentioned earlier, I need these in two separate jobs since they each require a different build environment as you can see in my code snippet above. It would be great to have an option to exit the circleci entirely.
Ah, fair enough. I don’t recall seeing an exit mechanism.
If you have to use separate jobs, then for now I would suggest using workspaces to record whether the next job should run or not. Then the next job in the workflow can read that and use conditional steps to skip its main tasks. You’d have to do that for all your downstream jobs.
It’s not quite what you are after, but I’d guess your null jobs can be made to run in just a few seconds (since they are barely doing anything). This is better than them failing incorrectly, as you say.