Pass PR labels to a triggered child build

Hi,

I’m trying to have a step in triggered child pipeline being dependent on the PR label.

The child pipeline is triggered by a trigger step and as per the documentation, the branch and pull request environment variables are passed through:

  - trigger: "web-tests"
    label: ":hammer: Test"
    async: true
    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}"

However, this doesn’t seem to work with the build.pull_request variables on the child pipeline.

I’ve tried the following expressions:

build.pull_request.labels includes "my-label"
build.pull_request.draft

and they both don’t work.

Am I missing something?

1 Like

Hi Olivier,

I am afraid we currently don’t have built-in support for this and you will need to use the GitHub Labels API to find those labels and triggered the right pipeline.

I’m sorry it’s not available right now, but I have filed your usecase internally as a feature request to the team that I hope we can add this in the future for you.

Best,
Juanito

Thanks Juanito.

In the meantime, I got something working by using build meta-data and dynamic pipeline.

On the first pipeline, I have one step that use the conditional to set metadata:

  - label: ":triangular_flag_on_post:"
    command: buildkite-agent meta-data set "my-flag" "true"
    if: "build.pull_request.labels includes \"my label\""

I’ve then modified my trigger step to dynamically upload itself to the pipeline and set the env variables based on the meta-data set in that previous step.

- command: ".buildkite/trigger-tests.sh"
  label: ":hammer: Test"

.buildkite/trigger-tests.sh:

#!/bin/bash

set -euo pipefail

# Set up a variable to hold the meta-data from previous steps
MY_FLAG="$(buildkite-agent meta-data get "my-flag" --default "")"

# Create a pipeline with the trigger step
PIPELINE="steps:
  - trigger: \"web-tests\"
    label: \":hammer: Test\"
    async: true
    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}
        MY_FLAG: ${MY_FLAG}
"

# Upload the new pipeline and add it to the current build
echo "$PIPELINE" | buildkite-agent pipeline upload
1 Like

Hi,

2 years later, it seems this limitation still exist, I was going crazy facing this issue until I found this topic. I would be nice to update the documentation with this corner case, or even better to fix it.

Hello, @tetienne! Thank you for your feedback! We’ll analyze what can be done about this!

Best!

1 Like