Anyway to terminate CircleCI entirely?

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:

  1. 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.

  2. 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?

1 Like

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:

build-and-copy-iOSPlugin:
    macos:
      xcode: "10.0.0"
    steps:
      - checkout
      - run: echo "Building iOS Plugin"
      - run:
          command: |
            cd CircleCI
            ls
            chmod 755 *.*
            ./build-and-copy-iOSPlugin.sh
  build-and-copy-AndroidPlugin:
    docker:
      - image: circleci/android:api-24-ndk-r17b
    environment:
      JVM_OPTS: -Xmx3200m
    steps:
      - checkout
      - run: echo "Building Android Plugin"
      - run:
          command: |
            cd CircleCI
            ls
            chmod 755 *.*
            ./build-and-copy-AndroidPlugin.sh

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.

^ Would you edit this to use block formatting please? A (Markdown) formatting tool is available in the editor.

I just added markdown to the code snippet to make it readable

1 Like

Here’s the doc for the conditional feature in version 2.1 (I don’t think it is in preview any more though).

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.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.