Skip to content

Fallback via if: failure() without failing the job #25818

Answered by ethomson
bfloch asked this question in Actions
Discussion options

You must be logged in to vote

A failing step will cause the workflow to fail.  Instead of allowing the step to fail and then testing for it, you can set a variable when the docker pull fails, allow that step to succeed and then test for that variable.

For example:

- name: Pull docker image if available
        run: |
          docker pull A:TAG || echo "::set-env name=NEEDS_CONTAINER::true"
      - name: ... else build and push Docker image
        if: env.NEEDS_CONTAINER == 'true'
        run: |
          docker build --tag A:B .
          docker push A:B

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants