You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

GitHub Actions:workflow_dispatch复选框控制作业执行失败问题

问题原因分析
  1. 触发源不匹配导致条件失效:当通过push到release分支触发工作流时,github.event.inputs对象不存在,github.event.inputs.graphics为undefined,你的条件== true || == false无法匹配,作业直接跳过。
  2. 布尔输入的类型问题:GitHub Actions中workflow_dispatch的布尔类型输入会被解析为字符串("true"或"false"),直接用== true做比较会不匹配,导致条件判断错误。
解决方案

根据你的需求,分两种场景调整作业的if条件:

场景1:仅手动触发时根据复选框控制作业执行

只在手动触发工作流且勾选了graphics复选框时,执行graphics作业:

workflow_dispatch:
  inputs:
    graphics:
      type: boolean
      required: false
      default: false
    tags:
      description: 'trigger manually'
        
push:
  branches:
    - "release"

jobs:  
  graphics:
    if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.graphics == 'true' }}
    name: call graphicstransform deploy
    uses: ./.github/workflows/deploygraphics.yml
    secrets: inherit
    with:
      external: 'true'

场景2:push到release分支时强制执行,手动触发时根据复选框控制

如果需要push到release分支时自动执行该作业,同时手动触发时由复选框决定:

workflow_dispatch:
  inputs:
    graphics:
      type: boolean
      required: false
      default: false
    tags:
      description: 'trigger manually'
        
push:
  branches:
    - "release"

jobs:  
  graphics:
    if: ${{ github.event_name == 'push' || (github.event_name == 'workflow_dispatch' && github.event.inputs.graphics == 'true') }}
    name: call graphicstransform deploy
    uses: ./.github/workflows/deploygraphics.yml
    secrets: inherit
    with:
      external: 'true'
关键说明
  • 必须通过github.event_name区分触发源,避免非手动触发时inputs变量不存在导致的条件失效。
  • 布尔类型的输入值要以字符串形式比较('true'/'false'),而非直接用布尔值true/false。

内容的提问来源于stack exchange,提问作者Serve Laurijssen

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.19 15:12:15