-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathJenkinsfile
49 lines (49 loc) · 1.59 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
pipeline {
agent any
environment {
BUCKET_PATH = credentials('backend-path')
policy_file_path = credentials('policy_file_path')
}
options {
skipDefaultCheckout(true)
}
stages {
stage('clean workspace') {
steps {
cleanWs()
}
}
stage('checkout') {
steps {
checkout scm
}
}
stage('Terraform Plan') {
steps {
sh '''
cd guardrails/project-factory
terraform init -backend-config="bucket=${BUCKET_PATH}" -backend-config="prefix=project-factory-staging-tfstate" -var-file="staging.tfvars"
terraform plan -var-file="staging.tfvars" -out pfjenkins.tfplan
'''
}
}
stage('Terraform Validate') {
steps {
sh '''
cd guardrails/project-factory
terraform show -json "pfjenkins.tfplan" > "ffjenkins.json"
gcloud source repos clone gcp-policies "${policy_file_path}" --project="${GCP_PROJECT_NUMBER}"
gcloud beta terraform vet "pfjenkins.json" --policy-library="${policy_file_path}" --project="${GCP_PROJECT_NUMBER}"
'''
}
}
stage('Terraform Apply') {
steps {
sh '''
cd guardrails/project-factory
terraform apply -var-file="staging.tfvars" -auto-approve
'''
}
}
}
}