-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
98 lines (88 loc) · 2.57 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#! groovy
currentBuild.displayName = "Availability Canary [$currentBuild.number]"
FUNC_NAME="availability-canary"
String commitHash = ""
try {
if (ISSUE_NUMBER)
echo "Building from pull request..."
} catch (Exception ignored) {
ISSUE_NUMBER = false
echo "Building from jenkins job..."
}
pipeline {
agent any
options {
buildDiscarder(logRotator(numToKeepStr:'10'))
disableConcurrentBuilds()
quietPeriod(1)
}
parameters {
booleanParam(name: 'DeleteExisting', defaultValue: false, description: 'Delete existing stack?')
booleanParam(name: 'Deploy', defaultValue: true, description: 'Deploy latest artifact')
}
stages {
stage("Checkout") {
steps {
script {
prTools.checkoutBranch(ISSUE_NUMBER, "vizzyy-org/$FUNC_NAME")
commitHash = env.GIT_COMMIT.substring(0,7)
}
}
}
stage("Delete Stack") {
when {
expression {
return env.DeleteExisting == "true"
}
}
steps {
script {
sh("aws cloudformation delete-stack --stack-name $FUNC_NAME")
sh("aws cloudformation wait stack-delete-complete --stack-name $FUNC_NAME")
}
}
}
stage("Zip") {
steps {
script {
sh("zip -r lambda_function.zip availability-canary.py mysql* google proto* six* -q")
}
}
}
stage("Package") {
steps {
script {
sh("/usr/local/bin/sam package --s3-bucket vizzyy-packaging --output-template-file packaged.yml")
}
}
}
stage("Deploy") {
when {
expression {
return env.Deploy == "true"
}
}
steps {
script {
sh("/usr/local/bin/sam deploy --template-file packaged.yml --stack-name $FUNC_NAME --capabilities CAPABILITY_IAM")
}
}
}
}
post {
success {
script {
sh "echo '${env.GIT_COMMIT}' > ~/userContent/$FUNC_NAME-last-success-hash.txt"
echo "SUCCESS"
}
}
failure {
script {
echo "FAILURE"
}
}
cleanup { // Cleanup post-flow always executes last
deleteDir()
}
}
}