# Configuring build triggers

:::important[Existing trigger configurations]

This page details information about target-based build triggers, defined within a Workflow or a Pipeline. We recommend this approach for all new users as it offers a more granular and flexible build trigger system.

Existing configurations might use legacy, project-based triggers. Read more about them: [Legacy project-based triggers](/bitrise-ci/run-and-analyze-builds/build-triggers/legacy-project-based-triggers).

:::

## Creating build triggers

You create build triggers directly in a Workflow or Pipeline. Such triggers allow a single code event to trigger multiple Workflows or Pipelines. You can create triggers via the UI or in the configuration YAML file.

To create triggers:

**Workflow Editor**

1. 1. Log in to Bitrise and select **Bitrise CI** on the left, then select your project.
1. Click the **Workflows** button on the main page.
1. Select a Workflow.
1. Select the **Triggers** tab on the Workflow's page.

   ![trigger-in-workflow.png](/img/_paligo/uuid-fcb0bba9-a8a5-e874-c5ba-a5e0f08d8a80.png)
1. Select the trigger type and click the **Add trigger** button.
1. Configure your trigger in the dialog.

   Click the regex pattern button to turn on regular expressions when defining a value for the trigger condition.

   ![regex-button.png](/img/_paligo/uuid-2106af45-7e79-2a1c-5974-9a8f0bb78ffe.png)
1. When done, click **Add trigger**.

**Configuration YAML**

1. Open your configuration YAML file.
1. Find the Workflow.
1. In the Workflow, add a `triggers` property.

   ```yaml
   my-workflow:
     triggers:
   ```
1. Create your triggers. You can find the exact syntax for the different trigger types here: [YAML syntax for build triggers](/bitrise-ci/run-and-analyze-builds/build-triggers/yaml-syntax-for-build-triggers).

   For example, this trigger starts a build with the Workflow called `my-workflow`:

   ```yaml
   my-workflow:
     triggers:
       push:
       - commit_message: your_message
   ```

   You can use two properties for pattern matching:

   - `pattern` allows you to use simple wildcard matching.
   - `regex` allows you to use complex pattern matching with regular expressions.

   ```yaml
   my_awesome_workflow
     triggers:
       push:
         - branch: main
         - commit_message:
             pattern: "hello"
             last_commit: true
       pull_request:
         - source_branch: "*"
   ```
1. Save the configuration.

### Adding a new target-based trigger on the Triggers page

You can quickly add new target-based triggers without leaving the **Triggers** page. For example, after reviewing your active triggers, you can immediately add another one without switching context, speeding up your setup process.

1. Go to your project's **Triggers** page.
1. If you don't have triggers yet, you’ll see a new **Add Trigger** button in the middle on the **Triggers** page. Click **Add trigger** and fill out the dialog.

   ![addnewtrigger.png](/img/_paligo/uuid-2d246b3d-6d4f-d215-8ee7-7d628492f7aa.png)
1. If you already have target-based triggers, the **add trigger** button is above the triggers in the top-right corner. Click **add trigger** and fill out the dialog.

   ![addanothertrigger.png](/img/_paligo/uuid-8a1664ba-48bd-f04b-5453-60cd9641e2ca.png)

Adding a trigger here creates a specific workflow, which then appears under that workflow’s **Triggers** tab on the **Workflows** page for easy management.

## Disabling a trigger

You can temporarily disable any build trigger. A disabled trigger doesn't trigger builds but retains all configuration information. You can reactivate a disabled trigger at any time.

To disable a build trigger:

**Workflow Editor**

1. Open the Workflow Editor on Bitrise.
1. Select a Workflow or Pipeline.
1. On the Workflow page, select the **Triggers** tab.

   ![workflow-properties.png](/img/_paligo/uuid-7755ec1f-eb8f-5036-05b3-be1b330f2143.png)
1. Find the trigger you need and click the options menu (⋮) next to its name.

   ![workflow-properties-ellipsis.png](/img/_paligo/uuid-3ab9024b-207a-0b06-c099-714f8c053ecd.png)
1. Select **Disable trigger**.

**Configuration YAML**

1. Open your configuration YAML file.
1. Find the Workflow or Pipeline and its `triggers` property.
1. Add `enabled: false` to the trigger you want to disable.

   ```yaml
   triggers:
     push:
     - branch: main
       enabled: false
   ```

## Creating a trigger for the most recent Git commit

By default, when using the **Commit message** or **File change** condition in a code push trigger, Bitrise evaluates all commit messages and all changed files included in a single code push.

However, you can configure your triggers to evaluate only the last commit in a push. If a push contains multiple commits, only the most recent one will be evaluated.

**Workflow Editor**

1. [Create a new push trigger](/bitrise-ci/run-and-analyze-builds/build-triggers/configuring-build-triggers#creating-build-triggers).
1. Select either the **Commit message** or the **File change** condition.

   ![last-commit.png](/img/_paligo/uuid-31ba9329-7c53-4411-103e-df47df050799.png)
1. Under the condition, enable **Last commit only**.

**Configuration YAML**

1. Open your configuration YAML file and go to a Workflow.
1. Add a new push trigger. In the example, we're using the `commit_message` condition.

   ```yaml
   my-workflow:
     triggers:
       push:
       - commit_message: your_message
   ```
1. Add the `last_commit` property and set it to `true`.

   ```yaml
   my-workflow:
     triggers:
       push:
       - commit_message: your_message
         last_commit: true
   ```

## Triggering builds from draft PRs

GitHub and GitLab offers a feature called [draft pull request](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/about-pull-requests#draft-pull-requests) (or merge request in the case of GitLab): when you create a pull request (PR), you can choose to create a pull request that is ready for review or a draft pull request. Draft pull requests cannot be merged, and code owners are not automatically requested to review draft pull requests.

:::important[Git provider limitations]

This feature is only supported for GitHub and GitLab repositories.

:::

By default, opening a draft PR triggers builds. You can disable this at any time.

If opening a draft PR triggers a build, submitting it for review (converting it to "full" PR, in other words) will not trigger another. You can check out the exact code events that trigger builds depending on the draft PR trigger settings: [Build trigger behavior for draft PRs](#build-trigger-behavior-for-draft-prs).

Each separate trigger has its own toggle: you can configure your app so that certain triggers start a build from draft PRs while other triggers don't.

### Disabling builds from a draft PR

:::tip[Skipping Steps if a build is triggered by a draft PR]

This guide tells you how to disable triggering builds from a draft PR altogether. You can, however, also skip certain Steps in a build that is triggered by a draft pull request. You just need to use a `run_if` condition and the GITHUB_PR_IS_DRAFT Environment Variable: for more information, see [Enabling or disabling a Step conditionally](/bitrise-ci/workflows-and-pipelines/steps/enabling-or-disabling-a-step-conditionally).

:::

**Workflow Editor**

1. 1. Log in to Bitrise and select **Bitrise CI** on the left, then select your project.
1. Click the **Workflows** button on the main page.
1. Open your Workflow and select the **Triggers** tab.

   If you have a Pipeline, you can only disable the setting in the configuration YAML file.
1. Find the trigger you need and click the options menu (⋮) next to its name.
1. Select **Edit trigger** from the menu.

   ![edit-trigger.png](/img/_paligo/uuid-7e1fea02-d6ed-650a-043c-d8bb81c5f98e.png)
1. Uncheck the **Include draft pull requests** option and click **Apply changes**.

**Configuration YAML**

1. Open your configuration YAML file.
1. Find the `triggers` element in all Workflows or Pipelines you want to modify.
1. Add `draft_enabled: false` to the trigger entries you need.

   ```yaml
   triggers:
         pull_request:
         - target_branch: "develop"
           draft_enabled: false
         - target_branch: "main"
           draft_enabled: false
         - comment: 'run Bitrise'
   ```

   This will start workflows for non-draft PRs against the develop branch and the main branch, or anytime `run Bitrise` is commented on any PR.

### Build trigger behavior for draft PRs

The table shows whether a build is triggered when a specific action is performed regarding draft PRs, depending on the draft PR trigger settings. For example, converting a draft PR to a PR doesn't trigger a build if the draft PR trigger is enabled but it does trigger a build when it's disabled.

| Action | Draft PR trigger is enabled | Draft PR trigger is disabled |
| --- | --- | --- |
| Open a draft PR | ![tick.svg](/img/_paligo/uuid-cff0066a-5a70-e7b4-5140-5dabde7188c2.svg) | ![close-small.svg](/img/_paligo/uuid-5de915cb-051d-9584-d965-a36295c3f83c.svg) |
| Push a commit to a draft PR | ![tick.svg](/img/_paligo/uuid-cff0066a-5a70-e7b4-5140-5dabde7188c2.svg) | ![close-small.svg](/img/_paligo/uuid-5de915cb-051d-9584-d965-a36295c3f83c.svg) |
| Convert a draft PR to PR | ![close-small.svg](/img/_paligo/uuid-5de915cb-051d-9584-d965-a36295c3f83c.svg) | ![tick.svg](/img/_paligo/uuid-cff0066a-5a70-e7b4-5140-5dabde7188c2.svg) |
| Convert PR to draft PR | ![close-small.svg](/img/_paligo/uuid-5de915cb-051d-9584-d965-a36295c3f83c.svg) | ![close-small.svg](/img/_paligo/uuid-5de915cb-051d-9584-d965-a36295c3f83c.svg) |

## Supported trigger conditions

Not all trigger conditions are available for all Git providers. For details, check out the tables for both push triggers and pull request triggers.

### Push trigger conditions

| Git provider | Branch | Commit message | Files changed |
| --- | --- | --- | --- |
| GitHub (cloud and self-hosted) | ![tick.svg](/img/_paligo/uuid-cff0066a-5a70-e7b4-5140-5dabde7188c2.svg) | ![tick.svg](/img/_paligo/uuid-cff0066a-5a70-e7b4-5140-5dabde7188c2.svg) | ![tick.svg](/img/_paligo/uuid-cff0066a-5a70-e7b4-5140-5dabde7188c2.svg) |
| GitLab (cloud and self-hosted) | ![tick.svg](/img/_paligo/uuid-cff0066a-5a70-e7b4-5140-5dabde7188c2.svg) | ![tick.svg](/img/_paligo/uuid-cff0066a-5a70-e7b4-5140-5dabde7188c2.svg) | ![tick.svg](/img/_paligo/uuid-cff0066a-5a70-e7b4-5140-5dabde7188c2.svg) |
| Bitbucket (cloud and self-hosted) | ![tick.svg](/img/_paligo/uuid-cff0066a-5a70-e7b4-5140-5dabde7188c2.svg) | ![tick.svg](/img/_paligo/uuid-cff0066a-5a70-e7b4-5140-5dabde7188c2.svg) | ![close-small.svg](/img/_paligo/uuid-5de915cb-051d-9584-d965-a36295c3f83c.svg) |
| Assembla | ![tick.svg](/img/_paligo/uuid-cff0066a-5a70-e7b4-5140-5dabde7188c2.svg) | ![tick.svg](/img/_paligo/uuid-cff0066a-5a70-e7b4-5140-5dabde7188c2.svg) | ![close-small.svg](/img/_paligo/uuid-5de915cb-051d-9584-d965-a36295c3f83c.svg) |
| Deveo (Perforce) | ![tick.svg](/img/_paligo/uuid-cff0066a-5a70-e7b4-5140-5dabde7188c2.svg) | ![tick.svg](/img/_paligo/uuid-cff0066a-5a70-e7b4-5140-5dabde7188c2.svg) | ![tick.svg](/img/_paligo/uuid-cff0066a-5a70-e7b4-5140-5dabde7188c2.svg) |
| Gogs | ![tick.svg](/img/_paligo/uuid-cff0066a-5a70-e7b4-5140-5dabde7188c2.svg) | ![tick.svg](/img/_paligo/uuid-cff0066a-5a70-e7b4-5140-5dabde7188c2.svg) | ![close-small.svg](/img/_paligo/uuid-5de915cb-051d-9584-d965-a36295c3f83c.svg) |
| Azure DevOps | ![tick.svg](/img/_paligo/uuid-cff0066a-5a70-e7b4-5140-5dabde7188c2.svg) | ![tick.svg](/img/_paligo/uuid-cff0066a-5a70-e7b4-5140-5dabde7188c2.svg) | ![close-small.svg](/img/_paligo/uuid-5de915cb-051d-9584-d965-a36295c3f83c.svg) |

### Pull request trigger conditions

| Git provider | Source branch | Target branch | Labels | Comments | Commit message | Changed files |
| --- | --- | --- | --- | --- | --- | --- |
| GitHub (cloud and self-hosted) | ![tick.svg](/img/_paligo/uuid-cff0066a-5a70-e7b4-5140-5dabde7188c2.svg) | ![tick.svg](/img/_paligo/uuid-cff0066a-5a70-e7b4-5140-5dabde7188c2.svg) | ![tick.svg](/img/_paligo/uuid-cff0066a-5a70-e7b4-5140-5dabde7188c2.svg) | ![tick.svg](/img/_paligo/uuid-cff0066a-5a70-e7b4-5140-5dabde7188c2.svg) | ![tick.svg](/img/_paligo/uuid-cff0066a-5a70-e7b4-5140-5dabde7188c2.svg) | ![tick.svg](/img/_paligo/uuid-cff0066a-5a70-e7b4-5140-5dabde7188c2.svg) |
| GitLab (cloud and self-hosted) | ![tick.svg](/img/_paligo/uuid-cff0066a-5a70-e7b4-5140-5dabde7188c2.svg) | ![tick.svg](/img/_paligo/uuid-cff0066a-5a70-e7b4-5140-5dabde7188c2.svg) | ![tick.svg](/img/_paligo/uuid-cff0066a-5a70-e7b4-5140-5dabde7188c2.svg) | ![tick.svg](/img/_paligo/uuid-cff0066a-5a70-e7b4-5140-5dabde7188c2.svg) | ![tick.svg](/img/_paligo/uuid-cff0066a-5a70-e7b4-5140-5dabde7188c2.svg) | ![tick.svg](/img/_paligo/uuid-cff0066a-5a70-e7b4-5140-5dabde7188c2.svg) |
| Bitbucket (cloud and self-hosted) | ![tick.svg](/img/_paligo/uuid-cff0066a-5a70-e7b4-5140-5dabde7188c2.svg) | ![tick.svg](/img/_paligo/uuid-cff0066a-5a70-e7b4-5140-5dabde7188c2.svg) | N/A | ![tick.svg](/img/_paligo/uuid-cff0066a-5a70-e7b4-5140-5dabde7188c2.svg) | ![tick.svg](/img/_paligo/uuid-cff0066a-5a70-e7b4-5140-5dabde7188c2.svg) | ![tick.svg](/img/_paligo/uuid-cff0066a-5a70-e7b4-5140-5dabde7188c2.svg) |
| Assembla | ![close-small.svg](/img/_paligo/uuid-5de915cb-051d-9584-d965-a36295c3f83c.svg) | ![close-small.svg](/img/_paligo/uuid-5de915cb-051d-9584-d965-a36295c3f83c.svg) | N/A | ![close-small.svg](/img/_paligo/uuid-5de915cb-051d-9584-d965-a36295c3f83c.svg) | ![close-small.svg](/img/_paligo/uuid-5de915cb-051d-9584-d965-a36295c3f83c.svg) | ![close-small.svg](/img/_paligo/uuid-5de915cb-051d-9584-d965-a36295c3f83c.svg) |
| Deveo (Perforce) | ![close-small.svg](/img/_paligo/uuid-5de915cb-051d-9584-d965-a36295c3f83c.svg) | ![close-small.svg](/img/_paligo/uuid-5de915cb-051d-9584-d965-a36295c3f83c.svg) | ![close-small.svg](/img/_paligo/uuid-5de915cb-051d-9584-d965-a36295c3f83c.svg) | ![close-small.svg](/img/_paligo/uuid-5de915cb-051d-9584-d965-a36295c3f83c.svg) | ![close-small.svg](/img/_paligo/uuid-5de915cb-051d-9584-d965-a36295c3f83c.svg) | ![close-small.svg](/img/_paligo/uuid-5de915cb-051d-9584-d965-a36295c3f83c.svg) |
| Gogs | ![close-small.svg](/img/_paligo/uuid-5de915cb-051d-9584-d965-a36295c3f83c.svg) | ![close-small.svg](/img/_paligo/uuid-5de915cb-051d-9584-d965-a36295c3f83c.svg) | ![close-small.svg](/img/_paligo/uuid-5de915cb-051d-9584-d965-a36295c3f83c.svg) | ![close-small.svg](/img/_paligo/uuid-5de915cb-051d-9584-d965-a36295c3f83c.svg) | ![close-small.svg](/img/_paligo/uuid-5de915cb-051d-9584-d965-a36295c3f83c.svg) | ![close-small.svg](/img/_paligo/uuid-5de915cb-051d-9584-d965-a36295c3f83c.svg) |
| Azure DevOps | ![tick.svg](/img/_paligo/uuid-cff0066a-5a70-e7b4-5140-5dabde7188c2.svg) | ![tick.svg](/img/_paligo/uuid-cff0066a-5a70-e7b4-5140-5dabde7188c2.svg) | ![close-small.svg](/img/_paligo/uuid-5de915cb-051d-9584-d965-a36295c3f83c.svg) | ![close-small.svg](/img/_paligo/uuid-5de915cb-051d-9584-d965-a36295c3f83c.svg) | ![close-small.svg](/img/_paligo/uuid-5de915cb-051d-9584-d965-a36295c3f83c.svg) | ![close-small.svg](/img/_paligo/uuid-5de915cb-051d-9584-d965-a36295c3f83c.svg) |

:::note[No pull request triggers for Assembla, Deveo, and Gogs]

Assembla, Deveo (Perforce), and Gogs only support push-based triggers. Pull request triggers aren't available for these providers.

:::

:::important[GitHub stacked pull requests]

For a pull request in a [GitHub stack](https://docs.github.com/en/pull-requests/get-started/about-stacked-prs), Bitrise matches the target branch condition against the base branch of the stack, not against the branch the pull request targets directly.

Take a stack where `feature/part-2` targets `feature/part-1`, and the whole stack lands on `main`. A `target_branch: main` condition matches every pull request in the stack. A condition set to `feature/part-1` matches none of them.

:::
