docker - Github Actions 中的手动工作流触发器

标签 docker kubernetes continuous-integration github-actions

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

工作流程包括以下步骤:

  • 构建 docker 镜像
  • 将镜像推送到容器注册表
  • 推出 Kubernetes 部署。


  • 但是,我有两种不同的 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.

    https://i2.wp.com/user-images.githubusercontent.com/1865328/86147571-2de93700-babf-11ea-8a08-e4beffd3abe9.png?ssl=1

    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 (like on push and / or schedule)

    For instance:

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

    关于docker - Github Actions 中的手动工作流触发器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58933155/

    相关文章:

    python - 我正在尝试通过 docker compose 运行 Flask 应用程序和 kafka..但无法正确设置

    kubernetes - 如何使用 kubectl run 命令创建使用非默认服务帐户的 Pod?

    kubernetes - Kubernetes 中的 Apache Flink 部署 - 可用性和可扩展性

    iis - 如何添加新的 SQL Server 计算机帐户

    ios - XCode-bot 在物理设备上构建失败

    maven - 无法获得某些功能文件标签以通过TeamCity运行

    docker-compose 来自 shell 的 args

    docker - 在 jwilder/nginx-proxy Docker 容器中重写 URL

    swift - 使用 Vapor 3 更改主机名和端口

    docker - Kubernetes-Kafka 无法在主题上写入消息