Execute a job only if the previous job has failed

Replace this template with your information

Describe your question in as much detail as possible:

Hi there- Is there a way to run/execute a job only if the previous one had failed? Basically we went a “rollback” job to run to rollback a deployment if the testing job has failed.

  • What version are you on? Are you using self-managed or GitLab.com?

    • GitLab (Hint: /help): Using a self-managed version GitLab Enterprise Edition 13.0.8-ee
    • *Runner (Hint: /admin/runners): Using self-managed runners
  • Add the CI configuration from .gitlab-ci.yml and other configuration if relevant (e.g. docker-compose.yml)

stages:

  • deploy
  • testing
  • rollback

step-1:
stage: deploy
script:
- echo “deploy”

step-2:
stage: testing
script:
- echo “testing”

step-3:
stage: rollback
when: step-2 has failed with exit code 1
dependencies:
- step-2
script:
- echo “rollback”

  • What troubleshooting steps have you already taken? Can you link to any docs or other resources so we know where you have been?

N/A

Thanks for taking the time to be thorough in your request, it really helps! :blush: