Skip to main content

Legacy project-based triggers

Legacy triggers

This page is about legacy triggers that are defined on a project level. For new users, we strongly recommend using the target-based build triggers which are defined on the level of Workflows and Pipelines as they allow more flexibility in designing your triggers: Configuring build triggers.

Legacy or project-based triggers are defined on the project level: that is, the top level of your configuration YAML file. The trigger defines which Workflow or Pipeline should run when a given code event happens. A single code event can only trigger a single build.

Creating project-based triggersClick to copy link

Project-based triggers are defined on the project level: that is, the top level of your configuration YAML file. The trigger defines which Workflow or Pipeline should run when a given code event happens. A single code event can only trigger a single build.

  1. Log in to Bitrise and select Bitrise CI on the left, then select your project.

  2. Click the Workflows button on the main page.

    workflows-button.png

  3. Select a Workflow.

    push-trigger.png

  4. Select the trigger type and click the Add trigger button.

    For example, if you want to set up a trigger for pull request events, select the Pull Request tab.

  5. Click the Add trigger button.

  6. Configure your trigger in the dialog.

    When setting multiple conditions, all conditions must be fulfilled for a build to start. You can use regular expressions for any of the condition types.

    You can find the full list of supported trigger conditions here: Supported trigger conditions

  7. When done, click Add trigger.

Disabling a project-based triggerClick to copy link

To disable a project-based build trigger:

  1. Open the Workflow Editor on Bitrise.

  2. On the left, select Triggers.

  3. Select the appropriate tab, depending on the trigger you want to deactivate.

    two-pr-triggers.png

  4. Set the trigger to Inactive.

Project-based trigger syntaxClick to copy link

A project-based trigger has three main elements in its YAML syntax:

  • The type of the trigger: push, pull_request, or tag.
  • The trigger condition. For example, the source branch of a pull request.
  • The Workflow or Pipeline to be triggered.

One trigger means one build: a single project-based trigger can only trigger a single Workflow or Pipeline. You can chain Workflows together run several Workflows in succession from a single trigger.

Below is a single trigger that triggers a build with the primary Workflow when a pull request is opened from any branch.

trigger_map:
- pull_request_source_branch: "*"
type: pull_request
workflow: primary

Multiple matching triggersClick to copy link

For project-based triggers, the first trigger with matching conditions triggers a build. This means the order of the triggers is important:

trigger_map:
- type: push
push_branch: main
workflow: primary
- type: push
commit_message: deploy
workflow: deploy

The first trigger triggers the primary Workflow if code is pushed to the main branch of the app's repository.

The second trigger triggers the deploy Workflow if a commit with the commit message deploy is pushed to any branch of the repository.

What happens when a commit is pushed to the main branch with the commit message deploy? The commit matches all conditions of the first trigger so the primary Workflow is triggered. In this scenario, the deploy Workflow is NOT triggered, even though the commit matches all conditions of that trigger, too.

Multiple trigger conditionsClick to copy link

If you define multiple trigger conditions in a single project-based trigger then all conditions have to match in order to trigger a build. For example:

trigger_map:
- pull_request_target_branch: "main"
pull_request_source_branch: "develop"
type: pull_request
workflow: primary

This will only select the primary workflow if the pull request’s source branch is develop AND the target branch is main.

Project-based trigger componentsClick to copy link

The components listed on this page are valid for legacy, project-based triggers.

ComponentDescriptionAccepted valuesDefault value
typeDefines the type of a project-based trigger. A trigger with a given type only accepts trigger conditions belonging to that type.- push - pull_request - tagN/A
enabledA boolean property that defines if the trigger is currently active.- true - falsetrue
workflow or pipelineThe Workflow or Pipeline that is triggered. You can't set both.The exact name of the Workflow or Pipeline.N/A
ComponentDescriptionDefault value
push_branchThe branch of the repository where code is pushed to trigger a build.*
commit_messageThe commit message to trigger a build.*
changed_filesThe path to a file or folder where changes should trigger a build.*
ComponentDescriptionDefault value
pull_request_source_branchThe branch of from which the pull request is opened.*
pull_request_target_branchThe branch which is the merge target of the pull request.*
pull_request_labelThe pull request label.*
draft_pull_request_enabledA boolean property that defines if draft pull requests trigger builds.true
pull_request_commentA comment posted on a pull request.*
commit_messageA specific commit message in pushes to a pull request.*
changed_filesSpecific files that are modified in a pull request.*
ComponentDescriptionDefault value
tagThe value of the tag. Accepts a string value or a regex property.*