Run step only if previous step failed

Hi, I have this workflow for rolling back a kubernetes deployment if the integration tests fail:

- name: Integration Tests
      id: integrationTests
      run: |
        chmod +x gradlew
        ./gradlew integrationTest

- name: Rollback Deployment
      if: steps.integrationTests.outcome == 'failure'
      run: |
         kubectl rollout undo -n $DEPLOYMENT_NAMESPACE deployment/$DEPLOYMENT_NAME-$ENVIRONMENT

but it always ignores the rollback step, even if the integration tests fail… What am I missing?

I’ve also tried the conclusion keyword and wrapping the expression in ${{ }} but nothing works!

Thanks

Hello @obvionaoe ,
You may try to add continue-on-error: true to ‘Integration Tests’ step: it makes the workflow continue if that step fails.

1 Like

Take a look at the Job status check functions, in particular this note:

If your if expression does not contain any of the status functions it will automatically result with success().

So you should probably do something like this, to check both for failure in general and the specific step that failed:

- name: Rollback Deployment
  if: failure() && steps.integrationTests.outcome == 'failure'
  run: |
    kubectl rollout undo -n $DEPLOYMENT_NAMESPACE deployment/$DEPLOYMENT_NAME-$ENVIRONMENT
1 Like

Thanks a lot, that fixed it!

1 Like