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') }}
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With