I need to create a CI that erases the VMs that were created in the previous stage only if the previous stage succeeded. if I use when: on_success - It works only if all stages passed.
stages:
I want cleanup to work if all 5 test jobs passed even if I have a failure in a job that is in the build stage.
Use needs keyword https://docs.gitlab.com/ee/ci/yaml/#needs
vm:build:
stage: build
script: echo "Building vm..."
test_1:
stage: test
script: echo "test_1"
test_2:
stage: test
script: echo "test_2"
test_3:
stage: test
script: echo "test_3"
cleanup:
stage: cleanup
needs: ["test_1", "test_2", "test_3"]
script: echo "clea"