本文介紹了在 GitHub Actions 中檢索拉取請求編號的方法。主要方法是利用工作流程檔案中的pull_request_target 運算式透過GITHUB_PULL_REQUEST_NUMBER 存取拉取請求編號
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 Actions 工作流程中的拉取請求編號。例如:github.event.pull_request.number
<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 Actions 檢索拉取請求 ID 以在工作流程中使用,您可以使用
表達式。例如:github.event.pull_request.id
以上是如何在github actions中取得pr號的詳細內容。更多資訊請關注PHP中文網其他相關文章!