Github Actions 中的手动工作流触发器 [英] Manual workflow triggers in Github Actions

查看:19
本文介绍了Github Actions 中的手动工作流触发器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为项目存储库设置 Github Actions.

工作流程由以下步骤组成:

  • 构建 docker 镜像
  • 将映像推送到容器注册表
  • 推出 Kubernetes 部署.
<小时>

但是,我有两种不同的 Kubernetes 部署:一种用于开发,一种用于生产.因此,我还有两个 Github Action 工作流.

每次推送提交时都会触发 Github Action 开发工作流:

开启:推:分支机构:- 掌握

但我不希望将其用于我的生产工作流程.我需要一个手动触发器,例如 Send to production 按钮.我在文档中没有看到任何与此相似的内容.

<小时>

有没有办法在 Github Actions 中手动触发工作流?

如何在 Github Actions、Docker 或 Kubernetes 上拆分我的开发和生产工作流程以实现我想要的?

解决方案

有没有办法在 Github Actions 中手动触发工作流?

您可以考虑,

您可以选择在哪个分支上运行工作流.

philippe 添加 在评论中:

<块引用>

文档中没有提到的一件事:工作流必须存在于运行工作流"的默认分支上.按钮出现.
将其添加到此处后,您可以继续在其自己的分支上开发操作,并且更改将在使用按钮运行时生效

文档继续:

<块引用>

此外,您可以选择指定输入,GitHub 将在 UI 中显示为表单元素.工作流分派输入的指定格式与操作输入相同.

例如:

开启:工作流调度:输入:日志级别:描述:'日志级别'要求:真默认值:'警告'标签:描述:'测试场景标签'

<块引用>

触发的工作流接收 github.event 上下文中的输入.

例如:

工作:打印输入:运行:ubuntu-latest脚步:- 运行:|echo "日志级别:${{ github.event.inputs.logLevel }}"回声标签:${{ github.event.inputs.tags }}"


shim 添加到 评论:

<块引用>

您可以将 workflow_dispatch 添加到还有其他触发器(如 on push 和/或 schedule)的工作流中

例如:

开启:工作流调度:推:分支机构:- 掌握拉取请求:类型:[打开,同步,重新打开]

I am setting up Github Actions for a project repository.

The workflow consists of the following steps:

  • Building a docker image
  • Pushing the image to a container registry
  • Rollout a Kubernetes deployment.

However, I have two different Kubernetes deployments: one for development, and one for production. Hence, I have also two Github Action workflows.

The Github Action workflow for development is triggered everytime that a commit is pushed:

on:
  push:
    branches:
    - master

But I don't want that for my production workflow. I would need a manual trigger, like a Send to production button. I didn't see anything close to that in the docs.


Is there a way to trigger a workflow manually in Github Actions?

How can I split my development and my production workflows to achieve what I want, either on Github Actions, Docker or Kubernetes?

解决方案

Is there a way to trigger a workflow manually in Github Actions?

You might consider, from July2020:

GitHub Actions: Manual triggers with workflow_dispatch

(Note: or multiple workflows, through the new Composite Run Steps, August 2020)

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 adds 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

The documentation goes on:

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 adds in the comments:

You can add workflow_dispatch to a workflow that also has other triggers (like on push and / or schedule)

For instance:

on:
 workflow_dispatch:
 push:
   branches:
     - master
 pull_request:
   types: [opened, synchronize, reopened]

这篇关于Github Actions 中的手动工作流触发器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆