简体   繁体   English

如何在推送到另一个分支时触发 Github Actions 工作流?

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

When I push some code to master , one workflow file runs.当我将一些代码推送到master ,会运行一个工作流文件。 This file builds the artifacts and pushes the code to another branch production .该文件构建工件并将代码推送到另一个分支production

Another workflow file, which looks like the following, is set to run when any push happens to production .另一个工作流文件(如下所示)设置为在production发生任何推送时运行。

name: Deploy

on:
  push:
    branches:
      - production

jobs:

# Do something

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

But this workflow file is never run.但是这个工作流文件永远不会运行。 I expect that when the workflow file, listening to push event on master, is done, this file should run as the previous file pushes code to production branch.我希望当工作流文件在 master 上监听推送事件完成后,这个文件应该运行,因为前一个文件将代码推送到production分支。 How do I make sure that this happens?我如何确保发生这种情况?

You need to use a personal access token (PAT) for pushing the code in your workflow instead of the default GITHUB_TOKEN :您需要使用个人访问令牌 (PAT) 来推送工作流中的代码,而不是默认的GITHUB_TOKEN

Note: You cannot trigger new workflow runs using the GITHUB_TOKEN注意:您不能使用GITHUB_TOKEN触发新的工作流运行

For example, if a workflow run pushes code using the repository's GITHUB_TOKEN , a new workflow will not run even when the repository contains a workflow configured to run when push events occur.例如,如果工作流运行使用存储库的GITHUB_TOKEN推送代码,即使存储库包含配置为在push事件发生时运行的工作流,新的工作流也不会运行。

If you would like to trigger a workflow from a workflow run, you can trigger the event using a personal access token.如果您想从工作流运行中触发工作流,您可以使用个人访问令牌触发事件。 You'll need to create a personal access token and store it as a secret.您需要创建个人访问令牌并将其存储为机密。

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

相关问题 如何在 github 操作中推送到另一个存储库? - How to push to another repository in github actions? 如何使用 github 操作从 Github 中的存储库 A 的工作流作业触发存储库 B(下游作业)中的工作流作业 - How to trigger a workflow job in repository B(downstream job) from workflow job of repository A in Github using github actions Github 动作提交并推送到同一个分支 - Github actions commit and push to same branch 将更改推送到github中的另一个分支 - Push changes to another branch in github Jenkins 和 Github 从特定分支触发 PUSH - Jenkins and Github trigger PUSH from specific branch 触发GitHub PUSH上的Jenkins作业到特定分支 - Trigger Jenkins job on GitHub PUSH to specific branch Github 操作:在 workflow_run 上读取分支更改 - Github actions: read branch changes on workflow_run 如何让 github 操作工作流使用机器人名称将生成的文档推送到同一组织中的其他存储库 - How let github actions workflow push generated documentation to other repository in same organization using a bot name 如何将本地存储库推送到 Github 上另一个存储库的分支 - How to push a local repository to a branch of another repository on Github 在github gitflow工作流中,如何禁止团队成员推送到中央仓库主分支? - In github gitflow workflow how to forbid team member to push to central repo master branch?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM