# Pass PR labels to a triggered child build

**URL:** <https://forum.buildkite.community/t/pass-pr-labels-to-a-triggered-child-build/1486>\
**Category:** Pipelines\
**Created:** [March 9, 2021, 11:25am UTC](https://forum.buildkite.community/t/pass-pr-labels-to-a-triggered-child-build/1486 "2021-03-09T11:25:59Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![obrisse](https://avatars.discourse-cdn.com/v4/letter/o/35a633/32.png) [@obrisse](https://forum.buildkite.community/u/obrisse)\
**Post date:** [March 15, 2021, 9:31pm UTC](https://forum.buildkite.community/t/pass-pr-labels-to-a-triggered-child-build/1486/3 "2021-03-15T21:31:13Z")

</div>

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](https://buildkite.com/docs/pipelines/block-step#passing-block-step-data-to-other-steps-passing-meta-data-to-trigger-steps) 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
```

---

_[View the full topic](https://forum.buildkite.community/t/pass-pr-labels-to-a-triggered-child-build/1486)._
