How to get the GitHub Pull Request ID Number

Hi,

Is there a way to get and set the Github’s pull request number (example PR #323 ) into Github Actions’s Environment Variable (without the hashtag)?

env:
GITHUB_PR_NUMBER: 323

The PR number should be in the event payload. The payload is present in the context.
Check this link:
https://docs.github.com/en/developers/webhooks-and-events/webhook-events-and-payloads#pull_request

I don’t think it’s exposed by itself in the runner context or env variables so you probably need to parse the event payload object and extract the PR number from that.

@eb-trigo,

When a workflow is triggered by an event related to pull request (pull_request, pull_request_review, pull_request_review_comment or pull_request_target), you can use the expression (github.event.pull_request.number) to get the pull request number from the github context.
For example:

on: pull_request

env:
  PR_NUMBER: ${{ github.event.pull_request.number }}

jobs:
  job1:
    . . .
    steps:
      - name: view the PR number
        run: |
          echo "PR number = ${{ github.event.pull_request.number }}"
          echo "PR number = ${{ env.PR_NUMBER }}"
1 Like

@eb-trigo,

How are things going?
Have you try my above suggestion that using the expression (github.event.pull_request.number) to get the pull request number from the github context? Is it helpful to you?
Please try it, and any update, feel free to tell me.

In addition, if the workflow is not triggered by the events related to pull request, you can execute the “Get a pull request” API to get the information from the response of this API.