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.
Hi @commanda,
Thanks for asking this here!
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:
- Exposing an environment variable from a step, e.g. from a Script step, using
envman
: Environment Variables - Bitrise Docs - Using
run_if
to dynamically run/skip steps: http://devcenter.bitrise.io/tips-and-tricks/disable-a-step-by-condition/
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!