# How to programmatically abort instead of fail a build?

**URL:** <https://discuss.bitrise.io/t/how-to-programmatically-abort-instead-of-fail-a-build/1791>\
**Category:** Question & Answer\
**Created:** [May 19, 2017, 4:15pm UTC](https://discuss.bitrise.io/t/how-to-programmatically-abort-instead-of-fail-a-build/1791 "2017-05-19T16:15:39Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![commanda](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.bitrise.io/commanda/32/559_2.png) [@commanda](https://discuss.bitrise.io/u/commanda)\
**Post date:** [May 19, 2017, 4:15pm UTC](https://discuss.bitrise.io/t/how-to-programmatically-abort-instead-of-fail-a-build/1791/1 "2017-05-19T16:15:39Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![viktorbenei](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.bitrise.io/viktorbenei/32/18_2.png) [@viktorbenei](https://discuss.bitrise.io/u/viktorbenei)\
**Post date:** [May 19, 2017, 4:45pm UTC](https://discuss.bitrise.io/t/how-to-programmatically-abort-instead-of-fail-a-build/1791/2 "2017-05-19T16:45:55Z")

</div>

Hi @commanda,

Thanks for asking this here! 🙂

> [@commanda](#):
>
> Is it possible to programmatically abort a build, to have it just stop running, without that counting as a failure?

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](http://devcenter.bitrise.io/tips-and-tricks/expose-environment-variable/)
- Using `run_if` to dynamically run/skip steps: [http://devcenter.bitrise.io/tips-and-tricks/disable-a-step-by-condition/](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 ;)):

```auto
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!
