-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
43 lines (43 loc) · 1.19 KB
/
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
36
37
38
39
40
41
42
43
node {
stage('Checkout') {
git url: 'https://github.com/crerwin/tf_pipeline.git'
}
// stage('Clean Up') {
// if (fileExists("terraform.tfstate")) {
// sh "rm -f terraform.tfstate"
// }
// if (fileExists(".terraform/terraform.tfstate")) {
// sh "rm -f .terraform/terraform.tfstate"
// }
// }
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 -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'
}
}
}
}
}