Cancel a workflow in a job

Be able to cancel the following jobs of a workflow would enable conditional workflows or at least, graceful early exit of workflow

#You can avoid rebuilding everything with a large codebase/monorepo :
let say you have a project with a frontend and a backend. You have a workflow for each and both are quite long to run.

If you already have a tool to know which part you should build (by inspecting which files where changed by the commits you are building for instance) then you can gracefully stop the workflow that is not necessary (stop testing and building the whole backend when you only change the frontend)

#You can have conditional notification :
Let say you have a cleanup workflow which remove the very old versions of your application.
You may not want to run the whole pipeline if you can tell in a early job if there is anything to do in the rest of the pipeline.
With a cancel

From a user perspective and IMHO this can be a command in circleci-cli like the `step halt` command which proxy a command to the circleci-agent.

It might also be done once the workflow API is in place.

I think a workflow which was canceled by such command should be marked as cancelled.

Currently to mock that behavior I make my early step fail purposely to stop the rest of the pipeline. So I have notification of failed workflow even if the failure is "normal". Not ideal.

  • Timothée GERMAIN
  • Feb 1 2019
  • Taking votes
  • Attach files
  • Guest commented
    12 Aug 00:08

    We need this feature as well. Our use case is also monorepos and checking the commit to see if the commit changed files in a certain two folders. If not, we want to cancel the rest of the deploy workflow.

  • Guest commented
    November 21, 2019 11:50

    We also have a use case for this, one for dealing with monorepos and another for when our automated release tool that uses conventional commits to determine if a release is necessary.

    In the second case if the release tool determines there were not any 'releasable changes' i.e. a documentation or test update then the tool will not trigger a formal release or tag in github however our workflow will continue to deploy out to Prod which is obviously not good.

    Being able to conditionally run jobs would be ideal, but if not then being able to cancel or 'skip' jobs if they shouldn't happen would be great.

  • Pete Inge commented
    October 16, 2019 14:05

    I'd vote for this too. Personally, I can get what I need done by failing each individual job, however, this isn't ideal. Especially when the boss looks over my shoulder and see a lot of RED. Plus each job takes about a minute to spin up before I can check one boolean value to see if I should run. Seems highly inefficient.


    The filters on jobs is nice, but my specific use case is we have have a few more conditionals based on branch names and open PRs and we would like to add in custom tags in the commit messages.

  • David Fant commented
    August 07, 2019 08:12

    This would be great. My current workaround is having a step in every job that checks if the relevant files have changed. If so, we continue that job.

    # Example usage:
    # ./ path/to/dir1 path/to/dir2

    # 1. Get all the arguments of the script

    # 2. Get the latest commit
    LATEST_COMMIT=$(git rev-parse HEAD)

    # 3. Get the latest commit in the searched paths
    LATEST_COMMIT_IN_PATH=$(git log -1 --format=format:%H --full-diff $PATHS_TO_SEARCH)

    echo "Exiting this CircleCI job because code in the following paths have not changed:"
    circleci step halt

    For reference:

  • Roberto C. Morano commented
    June 20, 2019 13:58

    I tried the approach of self-cancelling the workflow so I don't need to make it fail, but got "Permission denied" from the API, so it seems it's just not supported :(