-
Notifications
You must be signed in to change notification settings - Fork 19
/
destroy.Jenkinsfile
88 lines (77 loc) · 2.26 KB
/
destroy.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
78
79
80
81
82
83
84
85
86
87
88
// engineerbetter/iac-example-ci:15-promote
def ciImage = 'engineerbetter/iac-example-ci@sha256:0bb2dd8e86b418cd96a3371887bf8d7aa929ef4c58616c98a425ff22bddc0257'
pipeline {
agent {
kubernetes {
yaml """
apiVersion: v1
kind: Pod
spec:
containers:
- name: iac
image: ${ciImage}
command:
- cat
tty: true
""".stripIndent()
defaultContainer 'iac'
}
}
environment {
TF_IN_AUTOMATION = 'true'
BOOTSTRAP_AWS_REGION = credentials 'BOOTSTRAP_AWS_REGION'
BOOTSTRAP_BUCKET_NAME = credentials 'BOOTSTRAP_BUCKET_NAME'
BOOTSTRAP_DYNAMO_TABLE_NAME = credentials 'BOOTSTRAP_DYNAMO_TABLE_NAME'
}
stages {
stage('Terraform init') {
environment {
AWS_ACCESS_KEY_ID = credentials 'AWS_ACCESS_KEY_ID'
AWS_SECRET_ACCESS_KEY = credentials 'AWS_SECRET_ACCESS_KEY'
}
steps {
sh 'make terraform-init'
}
}
stage('Delete sock shop') {
environment {
AWS_ACCESS_KEY_ID = credentials 'AWS_ACCESS_KEY_ID'
AWS_SECRET_ACCESS_KEY = credentials 'AWS_SECRET_ACCESS_KEY'
}
steps {
sh 'make fetch-cluster-config'
sh 'make delete-sock-shop'
// Leave time for Kubernetes to remove resources like Load Balancers.
// Since Kubernetes creates resources that terraform doesn't know
// about, we need to wait for these to be removed otherwise there's a
// risk that `terraform destroy` will hang and require manual cleanup.
sh 'sleep 180'
}
}
stage('Destroy cluster') {
environment {
AWS_ACCESS_KEY_ID = credentials 'AWS_ACCESS_KEY_ID'
AWS_SECRET_ACCESS_KEY = credentials 'AWS_SECRET_ACCESS_KEY'
TF_CLI_ARGS_destroy = '-input=false -auto-approve'
}
steps {
sh 'make destroy-cluster'
}
}
}
post {
always {
cleanWs()
}
failure {
slackSend(
message: "Destroy failed: <${env.BUILD_URL}|${env.JOB_NAME}#${env.BUILD_NUMBER}>",
color: 'danger',
username: 'The Butler',
tokenCredentialId: 'SLACK_WEBHOOK_CREDENTIAL',
baseUrl: 'https://hooks.slack.com/services/',
channel: env.SLACK_CHANNEL
)
}
}
}