-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathJenkinsfile
49 lines (44 loc) · 1.53 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
podTemplate(
name: 'build-pod',
label: 'build-pod',
containers: [
// containerTemplate(name: 'jnlp', image: 'jenkins/jnlp-slave:latest',args: '${computer.jnlpmac} ${computer.name}', workingDir: '/home/jenkins'),
containerTemplate(name: 'docker', image:'docker:19.03.8', command: 'cat', ttyEnabled: true, workingDir: '/home/jenkins/agent'),
containerTemplate(name: 'terraform', image: 'hashicorp/terraform:latest', ttyEnabled: true, command: 'cat', workingDir: '/home/jenkins/agent')
],
volumes: [
hostPathVolume(mountPath: '/var/run/docker.sock',hostPath: '/var/run/docker.sock')
],
envVars: [
envVar(key:'TF_VAR_region', value:'us-phoenix-1')
]
){
//node = the pod label
node('build-pod'){
stage('Checkout') {
checkout scm
}
//container = the container label
stage('TF Plan') {
container('terraform') {
sh 'terraform init'
sh 'terraform plan -out myplan'
}
}
stage('Docker build') {
container('docker') {
sh 'docker build -t docker-build:latest .'
}
}
// stage('Approval') {
// script {
// def userInput = input(id: 'confirm', message: 'Apply Terraform?', parameters: [ [$class: 'BooleanParameterDefinition', defaultValue: false, description: 'Apply terraform', name: 'confirm'] ])
// }
// }
stage('TF Apply') {
container('terraform') {
sh 'terraform apply -input=false myplan'
}
}
}
}