Trigger step
A trigger step creates a build on another pipeline.
You can use trigger steps to separate your test and deploy pipelines, or to create build dependencies between pipelines.
A trigger step can be defined in your pipeline settings, or in your pipeline.yml file, by setting the trigger attribute to the slug of the pipeline you want to trigger.
steps:
- trigger: deploy-pipeline
Permissions
Builds created by a trigger step inherit ownership details from the parent build. Buildkite Pipelines uses these details to identify a user and determine whether the trigger is allowed.
If a user unblocks a preceding block step or submits an input step, Pipelines identifies the most recent unblocker or submitter as the creator. Otherwise, Pipelines uses the creator of the parent build.
For parent builds created by GitHub push webhooks, the creator depends on your organization's build creator semantics:
- With strict build creator semantics, Pipelines identifies the authenticated webhook sender through their connected GitHub account.
- Without strict build creator semantics, Pipelines first uses the commit author information in the webhook payload to identify a Buildkite user. The commit author's email must match a verified email on the Buildkite account. If no verified email matches, Pipelines tries to identify the webhook sender through their connected GitHub account.
When Pipelines identifies a creator, it checks that user's permissions when a trigger step runs. If Pipelines cannot identify a creator and Teams is enabled, the trigger step can use the shared-team permissions described below.
If you have Teams enabled in your organization, one of the following conditions must be met:
- The identified user must be a member of your organization and have Build permission on every target pipeline.
- The triggering build has no creator and no unblocker, and the source pipeline and the target pipeline share a team with Build permission.
If neither condition is true, the build will fail, and builds on subsequent pipelines will not be triggered.
Without strict build creator semantics, adding a verified commit-author email can change authorization from the shared-team fallback to the identified user's permissions. To keep permission checks consistent, give identified commit authors Build permission on every target pipeline. With strict build creator semantics, give the authenticated webhook sender this permission. If a user unblocks a preceding block step or submits an input step, give that user this permission. For builds without an identified creator, make sure the source and target pipelines share a team with Build permission.
A matching pipeline trigger rule can allow one pipeline to trigger another without relying on user or team permissions.
Rules do not provide a separate deny action. Conditions limit when a rule allows a trigger, such as allowing triggers only from webhook-created source builds. Rules can apply to pipelines in the same or different clusters.
Rules do not prevent users from creating source builds or retrying jobs. Use user and team permissions to control those actions.
Trigger step attributes
Required attributes:
trigger |
The slug of the pipeline to create a build. You can find it in the URL of your pipeline, and it corresponds to the name of the pipeline, converted to kebab-case. Example: "another-pipeline"
|
Optional attributes:
build |
An optional map of attributes for the triggered build.
Available attributes: branch, commit, env, message, meta_data
|
label |
The label that will be displayed in the pipeline visualization in Buildkite. Supports emoji. Example: ":rocket: Deploy"Alias: name
|
async |
If set to true the step will immediately continue, regardless of the success of the triggered build. If set to false the step will wait for the triggered build to complete and continue only if the triggered build passed.Note that when |
branches |
The branch pattern defining which branches will include this step in their builds. Example: "main stable/*"
|
if |
A boolean expression that omits the step when false. See Using conditionals for supported expressions. Example: build.message != "skip me"
|
depends_on |
A list of step keys that this step depends on. This step will only run after the named steps have completed. See managing step dependencies for more information. Example: "test-suite"
|
key |
A unique string to identify the trigger step. Keys can not have the same pattern as a UUID ( xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx).Example: "trigger-deploy"Aliases: identifier, id
|
allow_dependency_failure |
Whether to continue to run this step if any of the steps named in the depends_on attribute fail.Default: false
|
skip |
Whether to skip this step or not. Passing a string provides a reason for skipping this command. Passing an empty string is equivalent to false.
On the modern build page, reveal skipped steps using Show skipped steps. In the Canvas view, a badge beside the eye icon on the Show skipped steps or Hide skipped steps control shows the skipped step count. Hover over a skipped step to see the reason, or select a skipped trigger step to see the reason in the step panel. See Viewing why a step was skipped.Example: trueExample: falseExample: "My reason"
|
soft_fail |
When true, failure of the triggered build will not cause the triggering build to fail.Default: false |
parallelism |
The number of parallel triggered builds to create. When set, Buildkite creates multiple triggered builds from a single trigger step. Each triggered build receives a BUILDKITE_PARALLEL_JOB environment variable (0-based index) and BUILDKITE_PARALLEL_JOB_COUNT (total number of parallel builds).Example: 3
|
Optional build attributes:
message |
The message for the build. Supports emoji. Default: the label of the trigger step. Example: "Triggered build" |
commit |
The commit hash for the build. Default: "HEAD"Example: "ca82a6d" |
branch |
The branch for the build. Default: The triggered pipeline's default branch. Example: "production" |
meta_data |
A map of meta-data for the build. Example: release-version: "1.1"
|
env |
A map of environment variables for the build. Example: RAILS_ENV: "test"
|
- trigger: "data-generator"
label: ":package: Generate data"
build:
meta_data:
release-version: "1.1"
Example: triggering parallel builds
steps:
- trigger: "data-generator"
label: ":package: Generate data"
parallelism: 3
build:
meta_data:
release-version: "1.1"
This creates three builds on the data-generator pipeline, each with a different BUILDKITE_PARALLEL_JOB value (0, 1, 2).
Agent-applied attributes
These attributes are only applied by the Buildkite agent when uploading a pipeline (buildkite-agent pipeline upload), since they require direct access to your code or repository to process correctly.
Agent-applied attributes are not accepted in pipelines set using the Buildkite interface.
if_changed
if_changed |
A glob pattern that omits the step from a build if it does not match any files changed in the build. Example: "{**.go,go.mod,go.sum,fixtures/**}"From version 3.109.0 of the Buildkite agent, if_changed also supports lists of glob patterns and include and exclude attributes.Minimum Buildkite agent versions: 3.99 (with --apply-if-changed flag), 3.103.0 (enabled by default), 3.109.0 (expanded syntax)
|
For an example pipeline, demonstrating various forms of if_changed, see Using if_changed.
Environment variables
You can use environment variable substitution to set attribute values:
- trigger: "app-deploy"
label: ":rocket: Deploy"
branches: "main"
async: true
build:
message: "${BUILDKITE_MESSAGE}"
commit: "${BUILDKITE_COMMIT}"
branch: "${BUILDKITE_BRANCH}"
To pass through pull request information to the triggered build, pass through the branch and pull request environment variables:
- trigger: "app-sub-pipeline"
label: "Sub-pipeline"
build:
message: "${BUILDKITE_MESSAGE}"
commit: "${BUILDKITE_COMMIT}"
branch: "${BUILDKITE_BRANCH}"
env:
BUILDKITE_PULL_REQUEST: "${BUILDKITE_PULL_REQUEST}"
BUILDKITE_PULL_REQUEST_BASE_BRANCH: "${BUILDKITE_PULL_REQUEST_BASE_BRANCH}"
BUILDKITE_PULL_REQUEST_REPO: "${BUILDKITE_PULL_REQUEST_REPO}"
BUILDKITE_PULL_REQUEST in triggered builds
If BUILDKITE_PULL_REQUEST is set, the agent will check out the corresponding pull request ref (that is, refs/pull/ID/head) instead of the branch specified by BUILDKITE_BRANCH.
This behavior is part of the agent's checkout logic, and is intended to support builds from pull requests. However, such behavior may be unexpected in triggered builds where BUILDKITE_PULL_REQUEST is passed for reporting purposes only.
To pass pull request metadata to a triggered build without affecting the code checkout, use a custom environment variable name (for example, MONOREPO_PULL_REQUEST instead of BUILDKITE_PULL_REQUEST).
To set environment variables on the build created by the trigger step, use the env attribute:
- trigger: "release-binaries"
label: ":package: Release"
build:
env:
RELEASE_STREAM: "${RELEASE_STREAM:-stable}"
Triggering specific steps in a pipeline
While you cannot trigger only a specific step in a pipeline, you can use conditionals or dynamic pipelines to achieve a similar effect.
An example using conditionals might look like this:
- Testing for BUILDKITE_SOURCE
=='trigger_job'to find out if the build was triggered by a trigger step - Testing for BUILDKITE_TRIGGERED_FROM_BUILD_PIPELINE_SLUG to find out which pipeline triggered the build
- Custom environment variables passed to the triggered build
In the target pipeline, to run the command step only if the build was triggered by a specific pipeline, you might use something like this:
steps:
- command: ./scripts/tests.sh
if: build.source == 'trigger_job' && build.env('BUILDKITE_TRIGGERED_FROM_BUILD_PIPELINE_SLUG') == 'the-triggering-pipeline'
If you also want the command step to run when the build was not triggered by the specific pipeline, you might need to do the opposite, and set conditions on the steps that you don't want to run when the build is triggered:
steps:
- command: ./scripts/tests.sh
if: build.source != 'trigger_job'
Canceling intermediate builds and triggers
When using trigger steps that target pipelines with Cancel Intermediate Builds setting enabled, it's important to understand how this feature interacts with triggered builds. If a triggered build is "canceled" due to the Cancel Intermediate Builds setting being enabled, such trigger step will be marked as "skipped" in the triggering build.
Multiple triggered builds for the same pipeline
When multiple pipeline builds (for instance, when multiple builds are running as a result of a single commit) trigger builds in other pipelines, you can enable the Cancel Intermediate Builds feature to allow only the newest build to run, thereby reducing unnecessary, duplicated pipeline builds.
For example, assume a scenario with three pipelinesβPipeline A, Pipeline B, and Pipeline C. A commit that runs Pipeline A triggers a build on Pipeline B. The same commit runs Pipeline C, which also triggers a build on Pipeline B.
When Cancel Intermediate Builds:
Is enabled, the build of Pipeline B, run by whichever pipeline it was triggered by first, is canceled and the newest triggered Pipeline B build would be allowed to run.
Is not enabled, Pipeline B will run twice, as it will be triggered by both Pipeline A and Pipeline C without cancellation.
Regardless of whether or not Cancel Intermediate Builds is enabled, if either Pipeline A or Pipeline C is manually canceled before their triggering steps have occurred, then the Pipeline B build triggered by its canceled pipeline will not run, and Pipeline B will only run once (triggered by the other, non-canceled pipeline).