I have a sample pipeline in gitlab. i want the the pipe to stop if any of the jobs fail. below is the code am using to replicate the scenario. the pipe does show failure as the status but the jobs continue to run even after a failed stage. example in the picture attached.
stages:
- unittest
- coverage_test
- static_code_analysis
variables:
skip_integration:
value: 'false'
description: "This variable for skipping integration tests"
skip_migration:
value: 'false'
unittest:
stage: unittest
script:
- echo "testing the code"
rules:
- if: '$CI_COMMIT_BRANCH == "master"'
when: always
- if: '$skip_integration == "true"'
when: never
- if: '$skip_integration == "false"'
when: always
lint_test:
stage: static_code_analysis
allow_failure: false
script:
- echo "this is a test"
rules:
- if: '$CI_COMMIT_BRANCH == "master"'
when: always
- if: '$skip_integration == "true"'
when: never
- if: '$skip_integration == "false"'
when: always
- when: on_success
coverage_test:
stage: coverage_test
script:
- echo00 "this is test again"
rules:
- if: '$CI_COMMIT_BRANCH == "master"'
when: always
- if: '$skip_integration == "true"'
when: never
- if: '$skip_integration == "false"'
when: always
- when: on_success
but the pipe does not stop on failure.
when: always
As the name implies, runs the job always. If you want to run the job when the previous stage succeeded, run it on_success. Change all always to on_success.
when: on_success
I've had success using needs for jobs that should only run if previous jobs succeed.
lint_test:
stage: static_code_analysis
allow_failure: false
script:
- echo "this is a test"
needs:
- coverage_test
rules:
- if: '$CI_COMMIT_BRANCH == "master"'
when: always
- if: '$skip_integration == "true"'
when: never
- if: '$skip_integration == "false"'
when: always
- when: on_success
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With