如果或条件 Github 操作

If or condition in Github Actions

我一直在尝试在 Github 操作中构建 CICD 管道,但我们无法处理相同的 if 和 or 条件。下面是我们的代码片段示例,

    name: Build Non prod
    needs: [rules]    
    if: ${{ (needs.rules.outputs.branch_name != 'production') || (needs.rules.outputs.branch_name != 'staging') }}
    steps:
      - name: Checkout
        uses: actions/checkout@v2

所以这个任务不应该运行在productionstaging分支,但是当运行s在staging分支时,这个工作也是与其他不适用于 staging 环境的工作一起被触发。

有什么方法可以让我们有 ifor 条件吗?

更新:

该条件将不起作用,低于更新的条件将起作用。

if: ${{ (needs.rules.outputs.branch_name != 'production') && (needs.rules.outputs.branch_name != 'staging') }}

您的情况应如下所示:

   name: Build Non prod
    needs: [rules]    
    if: ${{ (needs.rules.outputs.branch_name != 'production') && (needs.rules.outputs.branch_name != 'staging') }}
    steps:
      - name: Checkout
        uses: actions/checkout@v2

但是,如果您发现它不起作用,则可能与此问题有关 - Job-level "if" condition not evaluated correctly if job in "needs" property is skipped