CircleCI Ideas

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.

  • Avatar32.5fb70cce7410889e661286fd7f1897de Guest
  • Feb 1 2019
  • Taking votes
  • Attach files
  • Avatar40.8f183f721a2c86cd98fddbbe6dc46ec9
    Guest commented
    20 Jun 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 :(

  • Avatar40.8f183f721a2c86cd98fddbbe6dc46ec9
    Guest commented
    07 Aug 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: