-
Notifications
You must be signed in to change notification settings - Fork 0
/
full.Jenkinsfile
49 lines (49 loc) · 1.29 KB
/
full.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
44
45
46
47
48
49
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 ('bundle install') {
sh(script: 'bundle install --path ./gems')
}
stage('kitchen-terraform') {
sh(script: 'bundle exec kitchen test')
}
stage('Get State') {
sh 'terraform remote config -backend=local -backend-config="path=/var/lib/jenkins/tfstate/terraform.tfstate"'
sh 'terraform get'
}
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'
}
}
}
}
}