Skipping certain builds only for certain stages (or how to make circleci step halt work across jobs)

The way we deploy from staging to production is by doing a --ff-only merge. Because we have CircleCI update our git-dumped database schema after each PR is merged, the last commit in staging should always be ignored by CI. That can be easily done by adding “[ci skip]” to the commit name, but the problem is then that the --ff-only merge from staging to production won’t trigger a CI deployment. How do I ensure that some commits are skipped by certain stages?

Our attempt

Instead, we tried rolling our own equivalent “[skip-ci-staging]”, which should only skip the CI for the staging branch. Seeing as we already have separate workflows for staging/production, it’s easy to only add a condition to check for this flag to the workflow for staging. You can see the code below:

  ci_skip_check:
    docker:
      - image: circleci/python:3.6.1
    working_directory: ~/repo

    steps:
      - checkout

      # Skip auto-commit builds produced by our CI, but only for staging
      # (with a standard "[ci skip]", it won't trigger CI on fastforward merge)
      - run:
          command: |
            COMMIT_MSG=$(git log --format=oneline -n 1 $CIRCLE_SHA1)
            if [[ $COMMIT_MSG == *"[skip-ci-staging]"* ]]; then
              echo "[skip-ci-staging] detected. Stopping."
              circleci step halt
            fi

Our workflow consists of many different jobs and this job is put ahead of all of them with the others as requiring this one. It correctly detects the job and halts, but only halts the current job and not the entire workflow. We could make it raise an error instead to stop the workflow, but then that would trigger an email alert etc. every single time. We can’t have that. What’s the equivalent command to circleci step halt that makes the entire workflow stop?

3 Likes

Hi there,

This is an interesting feature, but right now nothing like this exists. The only approach that might work would be to “fail” the build as a part of your halt.

This seems like it would be really valuable so I would encourage you to make a feature request here: https://circleci.com/ideas/

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