Skip to main content

Conditionally End a Running Job Gracefully

Ending A Job Without Failure

Sometimes during a build, you may want to end the job early without generating a failure.

You can end a job gracefully by running the command: circleci-agent step halt.

You can combine this with if statements or when steps to control the lifecycle of the job conditionally.

Examples:

  • if statement:

run: |
    if [ "$CIRCLE_BRANCH" = "develop" ]; then
        circleci-agent step halt
    fi
  • when step:

- when:
    condition: false
    steps:
      - run:
          command: circleci-agent step halt

Additional Resources

Did this answer your question?