-
Notifications
You must be signed in to change notification settings - Fork 0
/
destroy.Jenkinsfile
35 lines (35 loc) · 990 Bytes
/
destroy.Jenkinsfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
node {
stage('Checkout') {
git url: 'https://github.com/crerwin/tf_pipeline.git'
}
stage('terraform init') {
//sh 'terraform remote config -backend=local -backend-config="path=/var/lib/jenkins/tfstate/terraform.tfstate"'
sh 'terraform init -backend=true -get=true'
}
stage('terraform plan') {
def planStatus = sh(script: 'terraform plan -destroy -out=plan.out -detailed-exitcode', returnStatus: true)
println planStatus
if (planStatus == 0) {
currentBuild.result = 'SUCCESS'
}
if (planStatus == 1) {
currentBuild.result = 'FAILURE'
}
if (planStatus == 2) {
stash name: "plan", includes: "plan.out"
try {
input message: 'Apply plan?', ok: 'Apply'
apply = true
} catch (err) {
apply = false
currentBuild.result = 'UNSTABLE'
}
if(apply) {
stage('terraform apply') {
unstash 'plan'
sh 'terraform apply plan.out'
}
}
}
}
}