-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile.delete
92 lines (88 loc) · 3.01 KB
/
Jenkinsfile.delete
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
89
90
91
92
import groovy.json.JsonOutput
import groovy.json.JsonSlurperClassic
pipeline {
agent any
options {
timestamps()
buildDiscarder(logRotator(daysToKeepStr: '90'))
disableConcurrentBuilds()
}
environment {
AWS_ACCESS_KEY_ID = credentials('secret-key-id')
AWS_SECRET_ACCESS_KEY = credentials('access-key')
PIP_ENV = """${sh(
returnStdout: true,
script: '''
set +x
export PATH=~/.local/bin:$PATH
pip3 install pipenv --user > /dev/null
pipenv update > /dev/null
pipenv install boto3 > /dev/null
'''
).trim()}"""
}
parameters {
string(
name: 'APP_FQDN',
description: 'application fqdn',
trim: true,
)
string(
name: 'REGION',
description: 'application fqdn',
trim: true,
defaultValue: 'us-east-1'
)
}
stages {
stage('Preparation') { // GET THE LOAB BALANCER NAME, PORT and, CERT TO DELETE
environment {
RAW_DATA = """${sh(
returnStdout: true,
script: '''
set +x
export PATH=~/.local/bin:$PATH
pipenv run python3 ./get_item.py --region=${REGION} --fqdn=${APP_FQDN}
'''
).trim()}"""
}
steps {
script {
def jsonObj = readJSON text: RAW_DATA
env.JSON_DATA = jsonObj
env.ELB = jsonObj.elb
env.APP_ENVIRONMENT = jsonObj.env
env.CERT_ARN = jsonObj.cert
env.PORT = jsonObj.port
env.LISTENER_RULE_ARN = jsonObj.lstnr_rule_arn
env.TG_GROUP_ARN = jsonObj.target_grp_arn
env.FQDN = jsonObj.fqdn
env.DDB_TABLE = jsonObj.table_name
env.LISTENER_ARN = jsonObj.listener_arn
}
}
}
stage('Cleanup AWS Resources') {
steps {
sh '''
export PATH=~/.local/bin:$PATH
pipenv run python3 ./delete_items.py \
--listener_rule_arn=${LISTENER_RULE_ARN} \
--target_group_arn=${TG_GROUP_ARN} \
--portnum=${PORT} \
--region=${REGION} \
--table_name=${DDB_TABLE} \
--json_data="${JSON_DATA}" \
--fqdn=${FQDN} \
--cert_arn=${CERT_ARN} \
--listener_arn=${LISTENER_ARN}
'''
}
}
}
post {
cleanup {
cleanWs(cleanWhenAborted: false)
}
}
}