How to add && (and) in if condition with success or failure

Hi all,
I’m trying to run an action if it satisfies two conditions mentioned in if block:

      - name: Check for all the jobs are succeeded
        if: ${{ success() &&  $INITIAL_COUNT != $FINAL_COUNT }}
        uses: peter-evans/create-or-update-comment@v1
          comment-id: "${{ }}"
          body: |  
            **Test Result:** All tests are passed
          reactions: hooray

But this gives error:

The workflow is not valid. .github/workflows/main.yml (Line: 164, Col: 13): Unexpected symbol: '$INITIAL_COUNT'. Located at position 15 within expression: success() &&  $INITIAL_COUNT != $FINAL_COUNT

if I run only one condition i.e success one then it’s running fine.

This issue seems to be more of the `INITIAL_COUNT` && FINAL_COUNT variables
For this case also it is giving some error:

      - name: Check if any test ran or not


The workflow is not valid. .github/workflows/main.yml (Line: 199, Col: 13): Unexpected symbol: '$INITIAL_COUNT'. Located at position 1 within expression: $INITIAL_COUNT == $FINAL_COUNT

So this is how these variables are set.

      - name: Record initial count
            RUN_INITIAL: ${{ github.run_number }}         
        run: echo ::set-env name=INITIAL_COUNT::$RUN_INITIAL

           ... some tasks ...

      - name: Record final count
            RUN_FINAL: ${{ github.run_number }}         
        run: echo ::set-env name=FINAL_COUNT::$RUN_FINAL

Can anyone help me to get the correct solution to this?

You set INITIAL_COUNT and FINAL_COUNT as environment variables, so in the if: clause you need to refer to them as env.INITIAL_COUNT and env.FINAL_COUNT, respectively. The if part isn’t a shell script like the run sections are, so you can’t use shell syntax for variables there.

1 Like