我正在为项目存储库设置 Github Actions。
工作流程包括以下步骤:
但是,我有两种不同的 Kubernetes 部署:一种用于开发,一种用于生产。因此,我还有两个 Github Action 工作流。
每次推送提交时都会触发用于开发的 Github Action 工作流:
on:
push:
branches:
- master
但我不希望在我的生产工作流程中出现这种情况。我需要一个手动触发器,比如发送到生产按钮。我在文档中没有看到任何与此接近的内容。
有没有办法在 Github Actions 中手动触发工作流?
我如何在 Github Actions、Docker 或 Kubernetes 上拆分我的开发和生产工作流以实现我想要的?
最佳答案
Is there a way to trigger a workflow manually in Github Actions?
你可以考虑,from July2020 :
GitHub Actions: Manual triggers with workflow_dispatch
(注:或多个工作流,通过 new Composite Run Steps ,2020 年 8 月)
You can now create workflows that are manually triggered with the new
workflow_dispatch
event.
You will then see a 'Run workflow
' button on the Actions tab, enabling you to easily trigger a run.You can choose which branch the workflow is run on.
philippe添加 in the comments :
One thing that's not mentioned in the documentation: the workflow must exist on the default branch for the "
Run workflow
" button to appear.
Once you add it there, you can continue developing the action on its own branch and the changes will take effect when run using the button
文档继续:
In addition, you can optionally specify inputs, which GitHub will present as form elements in the UI. Workflow dispatch inputs are specified with the same format as action inputs.
For example:
on:
workflow_dispatch:
inputs:
logLevel:
description: 'Log level'
required: true
default: 'warning'
tags:
description: 'Test scenario tags'
The triggered workflow receives the inputs in the
github.event
context.For example:
jobs:
printInputs:
runs-on: ubuntu-latest
steps:
- run: |
echo "Log level: ${{ github.event.inputs.logLevel }}"
echo "Tags: ${{ github.event.inputs.tags }}"
shim加入 the comments :
You can add
workflow_dispatch
to a workflow that also has other triggers (likeon push
and / orschedule
)on: workflow_dispatch: push: branches: - master pull_request: types: [opened, synchronize, reopened]
关于docker - Github Actions 中的手动工作流触发器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58933155/