-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathJenkinsfile-param
280 lines (237 loc) · 9.44 KB
/
Jenkinsfile-param
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
#!/usr/bin/env groovy
/**
* this is a cicd pipeline jenkinsfile for engage store morpheus poc
*/
import hudson.model.*
import groovy.json.JsonSlurperClassic
import groovy.json.JsonBuilder
import groovy.json.JsonOutput
import groovy.util.*
def slackNotificationChannel = 'engage-pipeline'
//def buildColor = currentBuild.result == null ? "good" : "warning"
//def buildStatus = currentBuild.result == null ? "SUCCESS" : currentBuild.result
//def buildStatus = currentBuild.result
def notifySlack(text, channel, attachments) {
def slackURL = 'https://hooks.slack.com/services/T3Uxxxxxx/B5xxxx/8hyuxxxx'
def jenkinsIcon = 'https://wiki.jenkins-ci.org/download/attachments/2916393/logo.png'
def payload = JsonOutput.toJson([text : text,
channel : channel,
username : "Jenkins",
attachments: attachments,
icon_url: jenkinsIcon ])
sh "curl -X POST --data-urlencode \'payload=${payload}\' ${slackURL}"
}
/**
//def author= "";
def author = sh(returnStdout: true, script: "git --no-pager show -s --format='%an' ${commit}").trim()
def message = sh(returnStdout: true, script: 'git log -1 --pretty=%B').trim()
*/
pipeline {
agent {
node { label 'ecrtest' }
}
/**
parameters {
choice(
// choices are a string of newline separated values
choices:'#deploy-frontend\n#deploy-statistics\n#deploy-dump',
description: '',
name: 'deploy-container')
}*/
/**
properties([
parameters([
string(name: 'branch', defaultValue: 'master', description :' the git source code branch')
])
]) */
options {
// Discard the old builds and keep only the 7 most recent builds
buildDiscarder(logRotator(numToKeepStr:'10'))
//retry the entire pipeline for 3 times on failure
retry(3)
//abort the pipeline if it's more than 2 hours
timeout(time: 3, unit: 'HOURS')
//disable concurrent executions of pipeline
disableConcurrentBuilds()
}
stages {
// checkout the git source code repo
/**stage('Checkout SCM') {
steps {
checkout scm
echo "checked out engage-cicdtest-store source git repo"
}
}*/
stage('Git Checkout') {
steps{
dir('engage-store') {
git branch: 'master', credentialsId: '', url: 'git@github.com:xxx/xxx.git'
}
dir('engage-backend-padrino') {
git branch: 'master', credentialsId: '', url: 'git@github.com:xxx/xxx.git'
}
dir('engage-backend-railsapi') {
git branch: 'master', credentialsId: '', url: 'git@github.com:xxx/xxx.git'
}
dir('campaign_manager') {
git branch: 'master', credentialsId: '', url: 'git@github.com:xxx/xxx.git'
}
dir('engage-cicdtest-store') {
git branch: 'master', credentialsId: '', url: 'git@github.com:xxx/xxx.git'
}
}
}
//Run the tests, integration, uitests locally
stage('Run Tests Locally') {
steps {
retry(3) {
dir('engage-cicdtest-store/bluefox/docker/tests') {
sh './docker_test.sh'
}
/**
dir('engage-store/bluefox/docker/integration') {
sh './docker_test.sh'
}
dir('engage-store/bluefox/docker/uitests') {
sh './docker_test.sh'
} */
}
}
}
stage('Abort or Proceed Deploy') {
steps {
dir('engage-cicdtest-store/scripts') {
script {
try {
sh 'python commit_message.py'
//sh 'exit 1'
} catch (err) {
echo "caught: ${err}"
currentBuild.result= 'ABORTED'
notifySlack("", slackNotificationChannel, [[
title: "Deploy containers ABORTED",
title_link: "${env.BUILD_URL}",
text: "${currentBuild.result}",
color: "grey"
]])
emailext(
subject: "Deployment Failed! - ${env.JOB_NAME} [${env.BUILD_NUMBER}]",
body: """FAILURE!: '${env.JOB_NAME} [${env.BUILD_NUMBER}]'
Check console output at <a href='${env.BUILD_URL}'>${env.JOB_NAME} [${env.BUILD_NUMBER}]/a>""",
to: "ramu.venumuddala@bluefox.io"
)
}
}
}
}
}
/**
//Build engage-store-frontend Image
stage('Deploy engage-store Containers') {
steps {
dir('engage-cicdtest-store/scripts') {
sh './commitmessage.sh'
}
}
} */
// Verify git commit id
stage('Verify commitid and prodtests') {
steps {
dir('engage-cicdtest-store/scripts') {
script {
try {
sh './verifycommitid_prodtest.sh'
} catch(err) {
echo "caught: ${err}"
sh './restore_recycle.sh'
currentBuild.result = 'FAILURE'
notifySlack("", slackNotificationChannel, [[
title: "Verify commitid and prodtests failed. Restore and Recycle!",
title_link: "${env.BUILD_URL}",
text: "${currentBuild.result}",
color: "danger"
]])
emailext(
subject: "Deployment Failed! - ${env.JOB_NAME} [${env.BUILD_NUMBER}]",
body: """Build failed due to verify commitid tests!: '${env.JOB_NAME} [${env.BUILD_NUMBER}]'
Check console output at <a href='${env.BUILD_URL}'>${env.JOB_NAME} [${env.BUILD_NUMBER}]/a>""",
to: "ramu.venumuddala@bluefox.io"
)
}
}
}
}
}
/*dir('engage-store') {
script {
//sh 'pwd > outFile'
//def last_commit = sh ( script: 'git rev-parse HEAD', returnStdout: true )
//def commit_message = sh ( script: 'git log -1 --pretty=%B', returnStdout: true )
//def morpheus_commitid= sh ( script: 'curl https://morpheus-frontend.bluefoxengage.com/api/v1/health_check | awk -F " " '{print \$3}'', returnStdout: true )
//if(last_commit == morpheus_commit)
//println "commitid tests are success and proceed to prodtests. cmess is ${commit_message} and mid is ${morpheus_commitid}"
// else
//sh 'exit 1'
//status = readFile 'outFile'
//println "current directory is ${status}"
}
} */
}
post {
/**always {
//notifySlack("Build Success!",slackChannel)
echo "Build ${env.JOB_NAME}"
//build junit files
junit 'engage-store/bluefox/docker/tests/*.xml'
junit 'engage-store/bluefox/docker/integration/*.xml'
junit 'engage-store/bluefox/docker/uitests/*.xml'
//build artifacts
archiveArtifacts artifacts: 'engage-store/bluefox/docker/uitests/artifacts/*', fingerprint: true
archiveArtifacts artifacts: 'engage-store/bluefox/docker/'
}*/
success {
notifySlack("", slackNotificationChannel, [[
title: "${env.JOB_NAME}, build #${env.BUILD_NUMBER}",
title_link: "${env.BUILD_URL}",
text: "SUCCESS",
color: "good"
]])
emailext(
subject: "${env.JOB_NAME} [${env.BUILD_NUMBER}] Success!",
body: """'${env.JOB_NAME} [${env.BUILD_NUMBER}]' Success!":</p>
<p>Check console output at <a href='${env.BUILD_URL}'>${env.JOB_NAME} [${env.BUILD_NUMBER}]/a></p>""",
to: "ramu.venumuddala@bluefox.io"
)
}
failure {
//echo "Build ${env.JOB_NAME} failed"
notifySlack("", slackNotificationChannel, [[
title: "${env.JOB_NAME}, build #${env.BUILD_NUMBER}",
title_link: "${env.BUILD_URL}",
text: "Deployment Failed and Rollback",
color: "danger"
]])
emailext(
subject: "Deployment Failed! - ${env.JOB_NAME} [${env.BUILD_NUMBER}]",
body: """FAILURE!: '${env.JOB_NAME} [${env.BUILD_NUMBER}]'
Check console output at <a href='${env.BUILD_URL}'>${env.JOB_NAME} [${env.BUILD_NUMBER}]/a>""",
to: "ramu.venumuddala@bluefox.io"
)
}
unstable {
//echo "Build ${env.JOB_NAME} failed"
notifySlack("", slackNotificationChannel, [[
title: "${env.JOB_NAME}, build #${env.BUILD_NUMBER}",
title_link: "${env.BUILD_URL}",
text: "Deployment Aborted!!",
color: "grey"
]])
emailext(
subject: "Deployment Aborted! - ${env.JOB_NAME} [${env.BUILD_NUMBER}]",
body: """Aborted!: '${env.JOB_NAME} [${env.BUILD_NUMBER}]'
Check console output at <a href='${env.BUILD_URL}'>${env.JOB_NAME} [${env.BUILD_NUMBER}]/a>""",
to: "ramu.venumuddala@bluefox.io"
)
}
}
}