Skip certain builds or only some Steps with the Draft PR Env Var

Now you can skip running unnecessary builds or certain Steps when committing small or Draft PRs by using the Env Var 'GITHUB_PR_IS_DRAFT'.

Now you can skip running unnecessary builds or certain Steps when committing small or Draft PRs by using the Env Var GITHUB_PR_IS_DRAFT. 🚀

We introduced a new environment variable - GITHUB_PR_IS_DRAFT - that will be set to true when a Draft Pull Request triggers a build. You can use this variable to vary the behavior of your builds based on the Pull Request’s draft status. As the Env Var’s name suggests, this feature is only available for apps hosted on GitHub at the moment.

Two use-cases are

  • to skip steps and
  • to early exit builds

making more efficient use of credits.

Note: you can select ‘Draft PR’ when opening a Pull Request and this Env Var is of course only present in builds triggered by PR webhooks.

Skipping steps

Let’s see how you can run builds, but skip certain steps to save credits and time. In the case of a Draft PR, you might want to skip lengthy UI Tests and just run some static analysis instead.

Sample script that will only run if it's a Draft PR:

- [email protected]:
        run_if: '{{getenv "GITHUB_PR_IS_DRAFT" | eq "true"}}'
        inputs:
        - content: |-
            #!/usr/bin/env bash
            echo "This is a draft PR"
Copy Code

And this is a sample script to only run if NOT a Draft PR:

- [email protected]:
        run_if: '{{getenv "GITHUB_PR_IS_DRAFT" | eq ""}}'
        inputs:
        - content: |-
            #!/usr/bin/env bash
            echo "Not a draft PR"
Copy Code

Early exit a Build

To skip an entire PR build if the Pull Request is in draft state, place a Script Step at the beginning of the Workflow. This script will early exit if the Pull Request is a Draft. This will have an overhead of 1 minute of build time consumed.

Sample script to exit build when a Draft PR is detected:

- [email protected]:
    inputs:
    - content: |-
        #!/usr/bin/env bash
        if [ "$GITHUB_PR_IS_DRAFT" = true ] ; then
        exit 1
        fi
Copy Code

Please note the following:

  1. This will cause your build to show as failed.
  2. Put this script as the first step in your Workflow, otherwise you’ll waste time on other Steps.
  3. If you have subsequent Steps marked as is_always_run, those Steps will still run.
  4. We do hope to have a simpler way for skipping an entire build in the future.

Happy building! 🚀

The Mobile DevOps Newsletter

Explore more topics

App Development

Learn how to optimize your mobile app deployment processes for iOS, Android, Flutter, ReactNative, and more

Bitrise & Community

Check out the latest from Bitrise and the community. Learn about the upcoming mobile events, employee spotlights, women in tech, and more

Bitrise Insights

Cache | Caching

Mobile App Releases

Learn how to release faster, better apps on the App Store, Google Play Store, Huawei AppGallery, and other app stores

Mobile DevOps

Learn Mobile DevOps best practices such as DevOps for iOS, Android, and industry-specific DevOps tips for mobile engineers

Mobile Testing & Security

Learn how to optimize mobile testing and security — from automated security checks to robust mobile testing and more.

Product Updates

Check out the latest product updates from Bitrise — Build Insights updates, product news, and more.

The Mobile DevOps Newsletter

Join 1000s of your peers. Sign up to receive Mobile DevOps tips, news, and best practice guides once every two weeks.