Dynamically trigger pipelines via buildkite-agent

The pipeline trigger step is great, but sometimes we don’t know which pipelines we want to trigger until mid-way through a build.

Currently we solve this by using the REST API during the execution of a step to invoke a new build. The down side of this is that the triggered builds don’t show up in the Buildkite UI for the current build.

It would be awesome if there was a command in buildkite-agent to do this. Something like:

buildkite-agent build create --pipeline my-pipeline \
  --commit HEAD \
  --branch master \
  --message "my message" \
  --env '{}' \
  --meta-data '{}'

These build would be asynchronous to the current build.

Hey @azz :wave:t2:

You can do this currently with dynamic pipeline uploads as a step in your pipeline:

cat <<YAML | buildkite-agent pipeline upload
steps:
  - name: ":rocket:"
    trigger: "${pipeline}"
    async: false
    branches: "${branch}"
    build:
      message: "My message for the build"
      commit: "${BUILDKITE_COMMIT}"
      branch: "${BUILDKITE_BRANCH}"
YAML 

Check out the script we use in the Agent pipeline: https://github.com/buildkite/agent/blob/master/.buildkite/steps/upload-release-steps.sh

1 Like

Perfect, thanks! For some reason I thought you couldn’t do this, but it works perfectly!

1 Like