How to programmatically abort instead of fail a build?

Is it possible to programmatically abort a build, to have it just stop running, without that counting as a failure? Currently, I have a script that runs as the first step in my Workflow, and it checks the commit message to see if it should run the build. All I can do is return 0 or 1 from the script. I want to be able to programmatically abort the build instead.

1 Like

Hi @commanda,

Thanks for asking this here! :slight_smile:

In general we consider aborted builds as failures, because otherwise it could be misleading / you might miss an important issue.

That said itโ€™s possible to do what you described, but requires a bit of configuration. The trick is to expose an env var in case you want to skip all other steps and then mark every step which should be skipped in that case with a run_if testing against the presence of that environment variable and skipping if present.

Docs:

A short example with only three Script steps, where the first one exposes a โ€œskipโ€ marker env var, and the second and third ones are configured to be skipped if that marker env var is present (with two different run_if statements, choose the one you like the most ;)):

format_version: "3"
default_step_lib_source: https://github.com/bitrise-io/bitrise-steplib.git
workflows:
  primary:
    steps:
    - script@1.1.3:
        title: Expose env var
        inputs:
        - content: |-
            #!/bin/bash
            set -ex

            envman add --key SKIP_OTHER_STEPS --value "skip"
    - script@1.1.3:
        title: This step will be skipped
        run_if: enveq "SKIP_OTHER_STEPS" "skip" | not
    - script@1.1.3:
        title: This step will also be skipped
        run_if: enveq "SKIP_OTHER_STEPS" ""

If you have any questions just let us know!

3 Likes