-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
68 lines (58 loc) · 2.17 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
pipeline {
agent any
environment {
METALCLOUD_API_KEY = credentials("METALCLOUD_API_KEY") // the METALCLOUD_API_KEY credentials defined in Jenkins
METALCLOUD_USER_EMAIL = credentials("METALCLOUD_USER_EMAIL") // the METALCLOUD_USER_EMAIL credentials defined in Jenkins
TF_VAR_datacenter = credentials("TF_VAR_datacenter")// the TF_VAR_datacenter credentials defined in Jenkins
TF_VAR_endpoint = credentials("TF_VAR_endpoint")
}
parameters {
booleanParam(name: 'SKIP_MANUAL_APPROVAL_STAGE', defaultValue: true,
description: 'if SKIP_MANUAL_APPROVAL_STAGE is true, no manual approval is needed before running terraform apply, destroy')
string(name: 'TERRAFORM_PATH', defaultValue: "terraform",
description: 'Absolute path to terraform binary')
}
stages {
stage("Run terraform init"){
steps{
sh "'${params.TERRAFORM_PATH}' init -input=false"
}
}
stage("Run terraform plan"){
steps{
sh "'${params.TERRAFORM_PATH}' plan -out='$JOB_NAME' -input=false"
}
}
stage("Terraform apply approval") {
when { expression { params.SKIP_MANUAL_APPROVAL_STAGE != true } }
steps {
script {
def userInput = input(id: "confirm", message: "Apply Terraform?", parameters: [ [$class: "BooleanParameterDefinition", defaultValue: false, description: "Apply terraform", name: "confirm"] ])
}
}
}
stage("Run terraform apply"){
steps{
sh "'${params.TERRAFORM_PATH}' apply '$JOB_NAME'"
}
}
stage("Terraform destroy approval") {
when { expression { params.SKIP_MANUAL_APPROVAL_STAGE != true } }
steps {
script {
def userInput = input(id: "confirm", message: "Run terraform destroy?", parameters: [ [$class: "BooleanParameterDefinition", defaultValue: false, description: "Destroy terraform", name: "confirm"] ])
}
}
}
stage("Run terraform destroy") {
steps {
sh "'${params.TERRAFORM_PATH}' destroy -force "
}
}
}
post {
always {
cleanWs()
}
}
}