Reputation: 153
I have a gitlab pipeline which consiste of multiple stages[checkout->build->test->Deploy->cleanup->validation->terminate ec2].I have 3 requirement.
Here is my example pipeline.
stages:
- checkout
- build
- test
- Deploy
- cleanup
- reset
- Jenkins Jobs
- validation
checkout:
stage: checkout
tags:
- publishing
script:
- echo checkout
build:
stage: build
tags:
- automated-content-publishing
script:
- echo build
test:
stage: test
tags:
- publishing
script:
- echo test
Deploy:
stage: Deploy
tags:
- publishing
script:
- echo deploy
Cleanup:
stage: Cleanup
tags:
- publishing
script:
- echo clean-up
when: on_failure
reset:
stage: Nexus Insert
tags:
- publishing
script:
- echo reset
Jenksin Jobs:
stage: Jenkins Jobs
tags:
- publishing
script:
- echo jenkins jobs
vilidation:
stage: Vilidation
tags:
- publishing
script:
- echo validation
this pipeline works perfectly in 2 and 3 requirements. pipeline not working for 1 requirement. if any stage failed before the deploy stage failed cleanup stage call.
I want to call the cleanup stage only and only when the deploy stage failed.
Please guide me to build this case.
Upvotes: 4
Views: 8000
Reputation: 333
You could use something like this
Deploy:
stage: Deploy
tags:
- publishing
script:
- echo deploy
...
Cleanup:
stage: Cleanup
tags:
- publishing
script:
- echo clean-up
needs:
- job: Deploy
when: on_failure
If deploy stage has many jobs just add them to needs
section. For more info look at reference.
Upvotes: 1