-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathJenkinsfile
77 lines (77 loc) · 1.91 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
69
70
71
72
73
74
75
76
77
pipeline {
agent any
tools {
"org.jenkinsci.plugins.terraform.TerraformInstallation" "terraform-0.13.4"
}
parameters {
string(name: 'WORKSPACE', defaultValue: 'development', description:'setting up workspace for terraform')
}
environment {
TF_HOME = tool('terraform-0.13.4')
TF_IN_AUTOMATION = "true"
PATH = "$TF_HOME:$PATH"
AWS_ACCESS_KEY_ID = credentials('AWS_ACCESS_KEY_ID')
AWS_SECRET_ACCESS_KEY = credentials('AWS_SECRET_ACCESS_KEY')
}
stages {
stage('Terraform Init'){
steps {
dir('app-ec2/'){
sh "terraform init -input=false"
sh "echo \$PWD"
sh "whoami"
}
}
}
stage('Terraform Format'){
steps {
dir('app-ec2/'){
sh "terraform fmt"
}
}
}
stage('Terraform Validate'){
steps {
dir('app-ec2/'){
sh "terraform validate"
}
}
}
stage('Terraform Plan'){
steps {
dir('app-ec2/'){
script {
try {
sh "terraform workspace new ${params.WORKSPACE}"
} catch (err) {
sh "terraform workspace select ${params.WORKSPACE}"
}
sh "terraform plan -input=false -var-file=dev.tfvars \
-out terraform.tfplan;echo \$? > status"
stash name: "terraform-plan", includes: "terraform.tfplan"
}
}
}
}
stage('Approval'){
steps {
script{
def apply = false
try {
input message: 'Can you please confirm the apply', ok: 'Ready to Apply the Config'
apply = true
} catch (err) {
apply = false
currentBuild.result = 'UNSTABLE'
}
if(apply){
dir('app-ec2/'){
unstash "terraform-plan"
sh 'terraform apply terraform.tfplan'
}
}
}
}
}
}
}