# Allow triggered child build to inherit PR-related env vars from parent build

**URL:** <https://forum.buildkite.community/t/allow-triggered-child-build-to-inherit-pr-related-env-vars-from-parent-build/168>\
**Category:** Features Requests\
**Created:** [December 14, 2018, 12:26am UTC](https://forum.buildkite.community/t/allow-triggered-child-build-to-inherit-pr-related-env-vars-from-parent-build/168 "2018-12-14T00:26:20Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![rmtobin](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.buildkite.community/rmtobin/32/408_2.png) [@rmtobin](https://forum.buildkite.community/u/rmtobin)\
**Post date:** [December 14, 2018, 12:26am UTC](https://forum.buildkite.community/t/allow-triggered-child-build-to-inherit-pr-related-env-vars-from-parent-build/168/1 "2018-12-14T00:26:20Z")

</div>

We recently added a pre-build pipeline before our various pipelines that get run whenever a PR is opened via a GitHub webhook, which then triggers a handful of other pipelines.

However, in the child pipelines that are triggered by the pre-build pipeline, any steps that attempt to check if the build is a PR or not via Buildkite env vars fail because only the initial pre-build pipeline seems to set  
`BUILDKITE_PULL_REQUEST, BUILDKITE_PULL_REQUEST_BASE_BRANCH, BUILDKITE_PULL_REQUEST_REPO` env vars. I’ve tried overriding these in the child pipelines via the `env` attribute in the trigger step, however these env vars appear to be read-only and cannot be overridden.

It’d be really handy if the trigger step allowed you to set any child builds to inherit these PR env vars, so the PR status of a build could get passed through to any subsequent pipelines.

---

<div class="post-metadata">

**Author:** ![anon85971592](https://avatars.discourse-cdn.com/v4/letter/a/dfb087/32.png) [@anon85971592](https://forum.buildkite.community/u/anon85971592)\
**Post date:** [December 17, 2018, 12:20am UTC](https://forum.buildkite.community/t/allow-triggered-child-build-to-inherit-pr-related-env-vars-from-parent-build/168/2 "2018-12-17T00:20:53Z")

</div>

> [@rmtobin](#):
>
> However, in the child pipelines that are triggered by the pre-build pipeline, any steps that attempt to check if the build is a PR or not via Buildkite env vars fail because only the initial pre-build pipeline seems to set  
> `BUILDKITE_PULL_REQUEST, BUILDKITE_PULL_REQUEST_BASE_BRANCH, BUILDKITE_PULL_REQUEST_REPO` env vars. I’ve tried overriding these in the child pipelines via the `env` attribute in the trigger step, however these env vars appear to be read-only and cannot be overridden.

Thanks for the post! This was originally by design, but now that I think more about about, I think it’s a bug.

Will try and get something shipped today!

---

<div class="post-metadata">

**Author:** ![pranit-harekar](https://avatars.discourse-cdn.com/v4/letter/p/6de8d8/32.png) [@pranit-harekar](https://forum.buildkite.community/u/pranit-harekar)\
**Post date:** [July 26, 2019, 5:40pm UTC](https://forum.buildkite.community/t/allow-triggered-child-build-to-inherit-pr-related-env-vars-from-parent-build/168/3 "2019-07-26T17:40:36Z")

</div>

@anon85971592 has this feature been added? If so please post the documentation link, I couldn’t find it.

Thanks

---

<div class="post-metadata">

**Author:** ![anon46008679](https://avatars.discourse-cdn.com/v4/letter/a/da6949/32.png) [@anon46008679](https://forum.buildkite.community/u/anon46008679)\
**Post date:** [July 26, 2019, 9:27pm UTC](https://forum.buildkite.community/t/allow-triggered-child-build-to-inherit-pr-related-env-vars-from-parent-build/168/4 "2019-07-26T21:27:36Z")

</div>

Hi here @pranit-harekar! Sorry for the delay in posting the details of how to do this. We did roll out support for this.

If you pass the following environment variables through to the triggered build, it will be associated with the pull request:

> [@anon85971592](#):
>
> BUILDKITE\_PULL\_REQUEST, BUILDKITE\_PULL\_REQUEST\_BASE\_BRANCH, BUILDKITE\_PULL\_REQUEST\_REPO

I’ve opened a pull request on our docs with the details:

> <https://github.com/buildkite/docs/pull/507/files>
>
> For https://forum.buildkite.community/t/allow-triggered-child-build-to-inherit-p…r-related-env-vars-from-parent-build/168

---

<div class="post-metadata">

**Author:** ![pranit-harekar](https://avatars.discourse-cdn.com/v4/letter/p/6de8d8/32.png) [@pranit-harekar](https://forum.buildkite.community/u/pranit-harekar)\
**Post date:** [July 29, 2019, 2:28pm UTC](https://forum.buildkite.community/t/allow-triggered-child-build-to-inherit-pr-related-env-vars-from-parent-build/168/5 "2019-07-29T14:28:57Z")

</div>

> [@anon46008679](#):
>
> BUILDKITE\_PULL\_REQUEST

Thank you very much!!
