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

GitHub Action定时执行时无法获取默认输入值求助

问题原因

Cron触发属于schedule事件,而你定义的inputs是workflow_dispatch事件专属配置——只有手动通过workflow_dispatch触发时,github.event.inputs才会包含输入值。当Cron自动触发时,github.event是schedule类型,不存在inputs属性,因此输出为空。

解决思路

以下是几种可行的解决方案:

方案1:按事件类型判断赋值

在步骤里直接根据触发事件类型选择值,Cron触发时使用预设默认值,手动触发时用用户输入值:

jobs:
  WebdriverIO-Automation:
    runs-on: ubuntu-latest
    steps:
      - name: Selection of Testing type
        run: |
          TEST_TYPE="${{ github.event_name == 'schedule' && 'stage-test' || github.event.inputs.typeOfTesting }}"
          echo "Branch Name: $TEST_TYPE"

方案2:全局环境变量统一管理

把默认值抽成全局环境变量,确保两种触发方式都能获取到,手动触发时可覆盖该值:

env:
  DEFAULT_TEST_TYPE: "stage-test"

on:
  workflow_dispatch:
    inputs:
      typeOfTesting:
        type: choice
        description: Select Type of Test
        default: "stage-test"
        required: true
        options:
          - stage-test-local-All
          - stage-test
          - stage-test-Uptime
  schedule:
    - cron: "0 1 * * *"
    - cron: "0 11 * * *"

jobs:
  WebdriverIO-Automation:
    runs-on: ubuntu-latest
    steps:
      - name: Selection of Testing type
        run: |
          TEST_TYPE="${{ github.event.inputs.typeOfTesting || env.DEFAULT_TEST_TYPE }}"
          echo "Branch Name: $TEST_TYPE"

方案3:Job级别变量赋值

在Job里定义变量,根据事件类型自动赋值:

jobs:
  WebdriverIO-Automation:
    runs-on: ubuntu-latest
    env:
      TEST_TYPE: ${{ github.event_name == 'schedule' && 'stage-test' || github.event.inputs.typeOfTesting }}
    steps:
      - name: Selection of Testing type
        run: |
          echo "Branch Name: ${{ env.TEST_TYPE }}"

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.20 01:40:31