繁体   English   中英

如果或条件在 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分支中运行,但是当动作在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

但是,如果您发现它不起作用,则可能与此问题有关 -如果跳过“需要”属性中的作业,则作业级别的“如果”条件未正确评估

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM