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:

- script@1:
        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:

- script@1:
        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:

- script@1:
    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! 🚀

Explore more topics

App development

Best practices from engineers on how to use Bitrise to build better apps, faster.

Community

Meet other Bitrise engineers, technology experts, power users, partners and join our BUGs.

Company

All the updates about Bitrise events, sponsorships, employees, and more.

Insights

Mobile development, latest tech, industry insights, and interviews with experts.

Mobile DevOps

Learn why mobile development is unique and requires a set of unique practices.

Releases

Stay tuned for the last updates, new features, and product improvements.

Get the latest from Bitrise

Join other Mobile DevOps engineers who receive regular emails from Bitrise, filled with tips, news, and best practices.