-
Notifications
You must be signed in to change notification settings - Fork 1
/
Jenkinsfile
190 lines (189 loc) · 8.13 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
def author() {
return sh(returnStdout: true, script: 'git log -n 1 --format="%an"').trim()
}
pipeline {
agent {
node {
label 'ehealth-build'
}
}
environment {
PROJECT_NAME = 'verification'
MIX_ENV = 'test'
DOCKER_NAMESPACE = 'edenlabllc'
POSTGRES_VERSION = '10'
POSTGRES_USER = 'postgres'
POSTGRES_PASSWORD = 'postgres'
POSTGRES_DB = 'postgres'
NO_ECTO_SETUP = 'true'
}
stages {
stage('Init') {
options {
timeout(activity: true, time: 3)
}
steps {
sh 'cat /etc/hostname'
sh 'sudo docker rm -f $(sudo docker ps -a -q) || true'
sh 'sudo docker rmi $(sudo docker images -q) || true'
sh 'sudo docker system prune -f'
sh '''
sudo docker run -d --name postgres -p 5432:5432 edenlabllc/alpine-postgre:pglogical-gis-1.1;
sudo docker run -d --name redis -p 6379:6379 redis:4-alpine3.9;
sudo docker ps;
'''
sh '''
until psql -U postgres -h localhost -c "create database otp_verification_api_dev";
do
sleep 2
done
'''
sh '''
mix local.hex --force;
mix local.rebar --force;
mix deps.get;
mix deps.compile;
'''
}
}
stage('Test') {
options {
timeout(activity: true, time: 3)
}
steps {
sh '''
(curl -s https://raw.githubusercontent.com/edenlabllc/ci-utils/umbrella_jenkins_gce/tests.sh -o tests.sh; chmod +x ./tests.sh; ./tests.sh) || exit 1;
'''
}
}
stage('Build') {
// failFast true
parallel {
stage('Build verification-app') {
options {
timeout(activity: true, time: 3)
}
environment {
APPS='[{"app":"otp_verification_api","chart":"verification","namespace":"verification","deployment":"api","label":"api"}]'
}
steps {
sh '''
curl -s https://raw.githubusercontent.com/edenlabllc/ci-utils/umbrella_jenkins_gce/build-container.sh -o build-container.sh;
chmod +x ./build-container.sh;
./build-container.sh;
'''
}
}
stage('Build verification-scheduler-app') {
options {
timeout(activity: true, time: 3)
}
environment {
APPS='[{"app":"otp_verification_scheduler","chart":"verification","namespace":"verification","deployment":"otp-verification-scheduler","label":"scheduler"}]'
}
steps {
sh '''
curl -s https://raw.githubusercontent.com/edenlabllc/ci-utils/umbrella_jenkins_gce/build-container.sh -o build-container.sh;
chmod +x ./build-container.sh;
./build-container.sh;
'''
}
}
}
}
stage('Run verification-app and push') {
options {
timeout(activity: true, time: 3)
}
environment {
APPS='[{"app":"otp_verification_api","chart":"verification","namespace":"verification","deployment":"api","label":"api"}]'
}
steps {
sh '''
curl -s https://raw.githubusercontent.com/edenlabllc/ci-utils/umbrella_jenkins_gce/start-container.sh -o start-container.sh;
chmod +x ./start-container.sh;
./start-container.sh;
'''
withCredentials(bindings: [usernamePassword(credentialsId: '8232c368-d5f5-4062-b1e0-20ec13b0d47b', usernameVariable: 'DOCKER_USERNAME', passwordVariable: 'DOCKER_PASSWORD')]) {
sh 'echo " ---- step: Push docker image ---- ";'
sh '''
curl -s https://raw.githubusercontent.com/edenlabllc/ci-utils/umbrella_jenkins_gce/push-changes.sh -o push-changes.sh;
chmod +x ./push-changes.sh;
./push-changes.sh
'''
}
}
}
stage('Run verification-scheduler and push') {
options {
timeout(activity: true, time: 3)
}
environment {
APPS='[{"app":"otp_verification_scheduler","chart":"verification","namespace":"verification","deployment":"otp-verification-scheduler","label":"scheduler"}]'
}
steps {
sh '''
curl -s https://raw.githubusercontent.com/edenlabllc/ci-utils/umbrella_jenkins_gce/start-container.sh -o start-container.sh;
chmod +x ./start-container.sh;
./start-container.sh;
'''
withCredentials(bindings: [usernamePassword(credentialsId: '8232c368-d5f5-4062-b1e0-20ec13b0d47b', usernameVariable: 'DOCKER_USERNAME', passwordVariable: 'DOCKER_PASSWORD')]) {
sh 'echo " ---- step: Push docker image ---- ";'
sh '''
curl -s https://raw.githubusercontent.com/edenlabllc/ci-utils/umbrella_jenkins_gce/push-changes.sh -o push-changes.sh;
chmod +x ./push-changes.sh;
./push-changes.sh
'''
}
}
}
stage('Deploy') {
options {
timeout(activity: true, time: 3)
}
environment {
APPS='[{"app":"otp_verification_api","chart":"verification","namespace":"verification","deployment":"api","label":"api"},{"app":"otp_verification_scheduler","chart":"verification","namespace":"verification","deployment":"otp-verification-scheduler","label":"scheduler"}]'
}
steps {
withCredentials([string(credentialsId: '86a8df0b-edef-418f-844a-cd1fa2cf813d', variable: 'GITHUB_TOKEN')]) {
withCredentials([file(credentialsId: '091bd05c-0219-4164-8a17-777f4caf7481', variable: 'GCLOUD_KEY')]) {
sh '''
curl -s https://raw.githubusercontent.com/edenlabllc/ci-utils/umbrella_jenkins_gce/autodeploy.sh -o autodeploy.sh;
chmod +x ./autodeploy.sh;
./autodeploy.sh
'''
}
}
}
}
}
post {
success {
script {
if (env.CHANGE_ID == null) {
slackSend (color: 'good', message: "Build <${env.RUN_DISPLAY_URL}|#${env.BUILD_NUMBER}> (<https://github.com/edenlabllc/otp_verification.api/commit/${env.GIT_COMMIT}|${env.GIT_COMMIT.take(7)}>) of ${env.JOB_NAME} by ${author()} *success* in ${currentBuild.durationString.replace(' and counting', '')}")
} else if (env.BRANCH_NAME.startsWith('PR')) {
slackSend (color: 'good', message: "Build <${env.RUN_DISPLAY_URL}|#${env.BUILD_NUMBER}> (<https://github.com/edenlabllc/otp_verification.api/pull/${env.CHANGE_ID}|${env.GIT_COMMIT.take(7)}>) of ${env.JOB_NAME} in PR #${env.CHANGE_ID} by ${author()} *success* in ${currentBuild.durationString.replace(' and counting', '')}")
}
}
}
failure {
script {
if (env.CHANGE_ID == null) {
slackSend (color: 'danger', message: "Build <${env.RUN_DISPLAY_URL}|#${env.BUILD_NUMBER}> (<https://github.com/edenlabllc/otp_verification.api/commit/${env.GIT_COMMIT}|${env.GIT_COMMIT.take(7)}>) of ${env.JOB_NAME} by ${author()} *failed* in ${currentBuild.durationString.replace(' and counting', '')}")
} else if (env.BRANCH_NAME.startsWith('PR')) {
slackSend (color: 'danger', message: "Build <${env.RUN_DISPLAY_URL}|#${env.BUILD_NUMBER}> (<https://github.com/edenlabllc/otp_verification.api/pull/${env.CHANGE_ID}|${env.GIT_COMMIT.take(7)}>) of ${env.JOB_NAME} in PR #${env.CHANGE_ID} by ${author()} *failed* in ${currentBuild.durationString.replace(' and counting', '')}")
}
}
}
aborted {
script {
if (env.CHANGE_ID == null) {
slackSend (color: 'warning', message: "Build <${env.RUN_DISPLAY_URL}|#${env.BUILD_NUMBER}> (<https://github.com/edenlabllc/otp_verification.api/commit/${env.GIT_COMMIT}|${env.GIT_COMMIT.take(7)}>) of ${env.JOB_NAME} by ${author()} *canceled* in ${currentBuild.durationString.replace(' and counting', '')}")
} else if (env.BRANCH_NAME.startsWith('PR')) {
slackSend (color: 'warning', message: "Build <${env.RUN_DISPLAY_URL}|#${env.BUILD_NUMBER}> (<https://github.com/edenlabllc/otp_verification.api/pull/${env.CHANGE_ID}|${env.GIT_COMMIT.take(7)}>) of ${env.JOB_NAME} in PR #${env.CHANGE_ID} by ${author()} *canceled* in ${currentBuild.durationString.replace(' and counting', '')}")
}
}
}
}
}