1
votes

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. 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.

Is there any way we can have if and or condition ?

Update:

The condition will not work, below updated condition will work.

if: ${{ (needs.rules.outputs.branch_name != 'production') && (needs.rules.outputs.branch_name != 'staging') }}
1
Could you share your rules stage/job? - Krzysztof Madej
Hey, the issue is solved. Had to use below condition for it to not run on staging and production environment. So when it's in Development or QA env, it's satisfying below condition and the job is skipped . yaml if: ${{ (needs.rules.outputs.branch_name != 'production') && (needs.rules.outputs.branch_name != 'staging') }} And when it's in Staging or Production environment below code snippet will tell actions to run and not skip yaml if: ${{ (needs.rules.outputs.branch_name != 'production') ||(needs.rules.outputs.branch_name != 'staging') }} - Sam-Sundar

1 Answers

0
votes

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