我遇到了 YAML 根据传递到 YAML 的参数值跳过作业的问题

问题描述 投票:0回答:1

在一个小测试程序中(如下):

name: run SS_Simple1_Manual.py

on:
  workflow_dispatch:
    inputs:
      param1:
        description: "First parameter"
        required: true
        type: string
      param2:
        description: "Second parameter"
        required: true
        type: string
      param3:
        description: "Third parameter"
        required: true
        type: string
      param4:
        description: "Fourth parameter"
        required: true
        type: string

jobs:
  main-thread:
    if: ${{inputs.param4}} == 'NOSKIP'
    runs-on: windows-latest
    steps:
      - name: checkout
        uses: actions/checkout@master
      - name: setup python
        uses: actions/setup-python@v4
        with:
          python-version: '3.7' # install the Python version needed
      - name: install python packages
        run: |
          python -m pip install --upgrade pip
          pip install -r requirements.txt
      - name: execute Python script
        run: python SS_Simple1.py "${{inputs.param1}}" "${{inputs.param2}}" "${{inputs.param3}}" "${{inputs.param4}}"

我希望仅在参数值为 NOSKIP 时才执行主线程。然而......虽然 YAML 是有效的,但我正在执行 Python。

python SS_Simple1.py“你好”“那里”“鲍勃”“希望” shell: C:\Program Files\PowerShell \pwsh.EXE -command ". '{0}'" 环境: python位置:C:\hostedtoolcache\windows\Python .7.9\x64 PKG_CONFIG_PATH:C:\hostedtoolcache\windows\Python .7.9\x64/lib/pkgconfig Python_ROOT_DIR:C:\hostedtoolcache\windows\Python .7.9\x64 Python2_ROOT_DIR:C:\hostedtoolcache\windows\Python .7.9\x64 Python3_ROOT_DIR:C:\hostedtoolcache\windows\Python .7.9\x64

['SS_Simple1.py', '你好', '那里', '鲍勃', '希望']

我已经尝试了一些比较......还没有达到目标。有人可以帮我吗?

我尝试过布尔值:==和eq。我还尝试了“param4”外观的几个版本,都被 YAML 解释器拒绝了

if-statement yaml
1个回答
0
投票

经过多次测试,我得到了答案。尽管参数变量在 Python 运行字符串中被称为 ${{inputs.param4}},但在 'if' 语句中它只是 inputs.param4。下面的完整逻辑以防对其他人有帮助......

name: run SS_Simple1_Manual.py

on:
  workflow_dispatch:
    inputs:
      param1:
        description: "First parameter"
        required: true
        type: string
      param2:
        description: "Second parameter"
        required: true
        type: string
      param3:
        description: "Third parameter"
        required: true
        type: string
      param4:
        description: "Fourth parameter"
        required: true
        type: string

jobs:
  NOSKIP-thread:
    if: inputs.param4 == 'NOSKIP'
    runs-on: windows-latest
    steps:
      - name: checkout
        uses: actions/checkout@master
      - name: setup python
        uses: actions/setup-python@v4
        with:
          python-version: '3.7' # install the Python version needed
      - name: install python packages
        run: |
          python -m pip install --upgrade pip
          pip install -r requirements.txt
      - name: execute Python script
        run: python SS_Simple1.py "${{inputs.param1}}" "${{inputs.param2}}" "${{inputs.param3}}" "${{inputs.param4}}"
  main-thread:
    if: inputs.param4 != 'NOSKIP'
    runs-on: windows-latest
    steps:
      - name: checkout
        uses: actions/checkout@master
      - name: setup python
        uses: actions/setup-python@v4
        with:
          python-version: '3.7' # install the Python version needed
      - name: install python packages
        run: |
          python -m pip install --upgrade pip
          pip install -r requirements.txt
      - name: execute Python script
        run: python SS_Simple1.py "${{inputs.param1}}" "${{inputs.param2}}" "${{inputs.param3}}" "${{inputs.param4}}"
© www.soinside.com 2019 - 2024. All rights reserved.