This article describes methods to retrieve the pull request number in GitHub Actions. The main approach involves utilizing the pull_request_target expression in the workflow file to access the pull request number via the GITHUB_PULL_REQUEST_NUMBER en
要在 GitHub Actions 中检索拉取请求编号,您可以使用以下步骤:
pull_request_target
工作流程文件中的表达式。例如:<code class="yaml">name: Pull Request Actions on: pull_request: paths: - "**.py" jobs: build-test: runs-on: ubuntu-latest if: ${{ github.event.pull_request.target.branch == 'main' }} steps: - name: Get pull request number id: get_pull_request_number uses: actions/github-script@v6 with: script: | console.log(`The pull Request number is ${process.env.GITHUB_PULL_REQUEST_NUMBER}`)</code>
GITHUB_PULL_REQUEST_NUMBER
环境变量获取拉取请求编号。您可以使用 github.event.pull_request.number
表达式访问 GitHub Actions 工作流程中的拉取请求编号。例如:
<code class="yaml">name: Pull Request Actions on: pull_request jobs: build-test: runs-on: ubuntu-latest steps: - name: Get pull request number run: echo "The pull Request number is ${{ github.event.pull_request.number }}"</code>
要从 GitHub Actions 检索拉取请求 ID 以在工作流程中使用,您可以使用 github.event.pull_request.id
表达式。例如:
<code class="yaml">name: Pull Request Actions on: pull_request jobs: build-test: runs-on: ubuntu-latest steps: - name: Get pull request ID run: echo "The pull Request ID is ${{ github.event.pull_request.id }}"</code>
以上是如何在github actions中获取pr号的详细内容。更多信息请关注PHP中文网其他相关文章!