How to get the GitHub Pull Request ID Number


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)?


The PR number should be in the event payload. The payload is present in the context.
Check this link:

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.


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

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

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


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.