Gitlab CI Manual Destroy Step
This example demonstrates a Gitlab CI pipeline with a manual destroy step. This ensures resources are only destroyed when explicitly confirmed.
Pipeline Structure
The pipeline consists of four stages: build, test, deploy, and destroy. The destroy stage contains two jobs: destroy
(dry-run) and destroy-confirmation
(actual destruction).
YAML Configuration
image: busybox:latest
stages:
- build
- test
- deploy
- destroy
before_script:
- echo "Before script section"
after_script:
- echo "After script section"
build1:
stage: build
script:
- echo "building"
test1:
stage: test
script:
- echo "testing"
test2:
stage: test
script:
- echo "parallel test"
deploy1:
stage: deploy
script:
- echo "deploying"
- deploytime=$(( ( RANDOM % 10 ) + 1 ))
- sleep $deploytime
destroy:
stage: destroy
when: manual
script:
- echo "destroy --dry-run"
destroy-confirmation:
stage: destroy
script: echo "destroy --force"
when: manual
needs:
- destroy
Manual Destroy Process
The destroy
job performs a dry-run, allowing you to review the destruction plan. Only after manual approval will the destroy-confirmation
job execute the actual destruction command.
Further Improvements
Consider adding more robust checks and error handling to the destroy scripts for production environments.