# Hold the value of BUILDKITE\_PULL\_REQUEST

**URL:** <https://forum.buildkite.community/t/hold-the-value-of-buildkite-pull-request/3712>\
**Category:** Pipelines\
**Created:** [May 29, 2024, 10:00am UTC](https://forum.buildkite.community/t/hold-the-value-of-buildkite-pull-request/3712 "2024-05-29T10:00:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ismail](https://avatars.discourse-cdn.com/v4/letter/i/779978/32.png) [@ismail](https://forum.buildkite.community/u/ismail)\
**Post date:** [May 29, 2024, 10:00am UTC](https://forum.buildkite.community/t/hold-the-value-of-buildkite-pull-request/3712/1 "2024-05-29T10:00:03Z")

</div>

Hi Team,

When I merge or close a PR, the value of the `BUILDKITE_PULL_REQUEST` variable becomes `false`. I’ve seen the documentation confirming this behavior. However, I need a way to retrieve the PR number associated with the `BUILDKITE_PULL_REQUEST` variable during the last run, specifically when the script is running from the main branch after the merge.

There are certain operations I need to perform upon closing or merging a PR, and the `false` value is disrupting the logic.

Could you please assist with this issue?

Thanks and regards,  
Ismail

---

<div class="post-metadata">

**Author:** ![tomwatt](https://avatars.discourse-cdn.com/v4/letter/t/c68b51/32.png) [@tomwatt](https://forum.buildkite.community/u/tomwatt)\
**Post date:** [May 29, 2024, 2:39pm UTC](https://forum.buildkite.community/t/hold-the-value-of-buildkite-pull-request/3712/2 "2024-05-29T14:39:35Z")

</div>

Hey @ismail

Thanks for using the Buildkite Community Forums!

There are a few ways that the Pull Request Number can be retrieved after the merging of a Pull Request, will list a few of them but aware that some might not be appropriate depending on your workflows.

1. Retrieving it from `BUILDKITE_MESSAGE` environment variable, if as a part of your commit message the Pull Request Number is included, as seen as a part of some GitHub Merge Commits e.g., `Merge pull request #4 from ...`

2. Using `buildkite-agent meta-data` to store the Pull Request Number in a Build e.g.,

```auto
- label: "set PR Number in Meta-Data"
  command: "buildkite-agent meta-data set pull-request-number $$BUILDKITE_PULL_REQUEST"

```

and then retrieve it in another, but this requires the Build ID or Job ID from where the meta-data is set e.g.,

```auto
- label: "get PR Number from Meta-Data"
  command: "buildkite-agent meta-data get pull-request-number --build [Build ID from another Build]"

```

1. Using a block or Input step, to require input and set meta-data e.g.,

```auto
- block: "Previous PR Number"
  fields:
      - text: "Pull Request Number"
        key: "pull-request-number"

```

which can be retrieved later in your Build e.g.,

```auto
buildkite-agent meta-data get "pull-request-number"

```

Let us know if any of these options helps.

Regards,

Tom
