简体   繁体   English

如果或条件在 Github 操作

[英]If or condition in Github Actions

I've been trying to build a CICD pipeline in Github actions and we're not able to process if and or conditions in the same.我一直在尝试在 Github 操作中构建 CICD 管道,但我们无法同时处理 if 和 or 条件。 below is the example of our code snippet,下面是我们的代码片段示例,

    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

So this task should not run in production and staging branch, but when actions runs in staging branch, this job is also getting triggered along with other jobs which are not meant for staging environment.所以这个任务不应该在productionstaging分支中运行,但是当动作在staging分支中运行时,这个作业也会与其他不适用于staging环境的作业一起被触发。

Is there any way we can have if and or condition?我们有什么办法可以有ifor条件?

Update:更新:

The condition will not work, below updated condition will work.该条件将不起作用,以下更新的条件将起作用。

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

You condition should look like below:您的状况应如下所示:

   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

However if you find it not working it could be related to this issue - Job-level "if" condition not evaluated correctly if job in "needs" property is skipped但是,如果您发现它不起作用,则可能与此问题有关 -如果跳过“需要”属性中的作业,则作业级别的“如果”条件未正确评估

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

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