【问题标题】:Running a GitHub Actions step only if specific steps failed仅在特定步骤失败时运行 GitHub Actions 步骤
【发布时间】:2020-11-28 12:24:57
【问题描述】:

仅当特定的先前步骤失败且退出代码不为零时,我才想运行一个步骤。 我已经尝试了下面的代码,但它不起作用。 我该怎么做?

- name: JobA
  id: seedBuild
  run: |
        echo "::set-output name=exit_code::$(echo -n "$?")"

- name: JobB
  id: allJobs
  run: |
        echo "::set-output name=exit_code::$(echo -n "$?")"

- name: Debug Job Failure
  run: |
        echo "******** Job Logs from ********"
  if: "${{ steps.seedBuild.outputs.exit_code != 0 || steps.allJobs.outputs.exit_code != 0 }}"

【问题讨论】:

    标签: github-actions


    【解决方案1】:

    按照https://docs.github.com/en/actions/reference/context-and-expression-syntax-for-github-actions#steps-context使用步骤的结果

    - name: JobA
      id: seedBuild
      run: |
            echo "failing on purpose"
            exit 1
    
    - name: JobB
      id: allJobs
      run: |
            echo "::set-output name=exit_code::$(echo -n "$?")"
    
    - name: Debug Job Failure
      run: |
            echo "******** Job Logs from ********"
      if: ${{ always() && (steps.seedBuild.outcome == 'failure' || steps.allJobs.outcome == 'failure') }}
    

    【讨论】:

    • if 条件不需要表达式语法。可以写成if: always() && (steps.seedBuild.outcome == 'failure' || steps.allJobs.outcome == 'failure')
    猜你喜欢
    • 1970-01-01
    • 2021-11-16
    • 2020-01-01
    • 2020-01-16
    • 2021-05-02
    • 2020-03-10
    • 2020-05-12
    • 2020-01-11
    • 2017-01-31
    相关资源
    最近更新 更多