簡體   English   中英

如何在推送到另一個分支時觸發 Github Actions 工作流?

[英]How to trigger a Github Actions workflow on push to another branch?

當我將一些代碼推送到master ,會運行一個工作流文件。 該文件構建工件並將代碼推送到另一個分支production

另一個工作流文件(如下所示)設置為在production發生任何推送時運行。

name: Deploy

on:
  push:
    branches:
      - production

jobs:

# Do something

  deploy:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@master

但是這個工作流文件永遠不會運行。 我希望當工作流文件在 master 上監聽推送事件完成后,這個文件應該運行,因為前一個文件將代碼推送到production分支。 我如何確保發生這種情況?

您需要使用個人訪問令牌 (PAT) 來推送工作流中的代碼,而不是默認的GITHUB_TOKEN

注意:您不能使用GITHUB_TOKEN觸發新的工作流運行

例如,如果工作流運行使用存儲庫的GITHUB_TOKEN推送代碼,即使存儲庫包含配置為在push事件發生時運行的工作流,新的工作流也不會運行。

如果您想從工作流運行中觸發工作流,您可以使用個人訪問令牌觸發事件。 您需要創建個人訪問令牌並將其存儲為機密。

https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows#triggering-new-workflows-using-a-personal-access-token

name: Push to master

on:
  push:
    branches:
      - master

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    # the checkout action persists the passed credentials by default
    # subsequent git commands will pick them up automatically
    - uses: actions/checkout@v2
      with:
        token: ${{secrets.PAT}}
    - run: |
        # do something
        git push

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM