forked from ocf/ocfweb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
113 lines (97 loc) · 3.55 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
if (env.BRANCH_NAME == 'master') {
properties([
pipelineTriggers([
upstream(
upstreamProjects: 'ocflib/master,dockers/master',
threshold: hudson.model.Result.SUCCESS,
),
]),
])
}
try {
def sha
node('slave') {
step([$class: 'WsCleanup'])
stage('check-out-code') {
// TODO: I think we can factor out the "src" subdirectory now that we
// don't build a Debian package?
dir('src') {
checkout scm
sha = sh(script: 'git rev-parse --short HEAD', returnStdout: true).trim()
// TODO: figure out how to get the git plugin to do this for us
sh 'git submodule update --init'
}
}
stash name: 'src', useDefaultExcludes: false
}
def version = "${new Date().format("yyyy-MM-dd-'T'HH-mm-ss")}-git${sha}"
withEnv([
'DOCKER_REPO=docker-push.ocf.berkeley.edu/',
"DOCKER_REVISION=${version}",
]) {
parallel(
test: {
node('slave') {
step([$class: 'WsCleanup'])
unstash 'src'
stage('test') {
dir('src') {
sh 'make test'
}
}
}
},
cook_image: {
node('slave') {
step([$class: 'WsCleanup'])
unstash 'src'
stage('cook-image') {
dir('src') {
sh 'make cook-image'
}
}
}
},
)
if (env.BRANCH_NAME == 'master') {
node('deploy') {
step([$class: 'WsCleanup'])
unstash 'src'
stage('push-to-registry') {
dir('src') {
sh 'make push-image'
}
}
stage('deploy-to-prod') {
// TODO: make these deploy and roll back together!
build job: 'marathon-deploy-app', parameters: [
[$class: 'StringParameterValue', name: 'app', value: 'ocfweb/web'],
[$class: 'StringParameterValue', name: 'version', value: version],
]
build job: 'marathon-deploy-app', parameters: [
[$class: 'StringParameterValue', name: 'app', value: 'ocfweb/worker'],
[$class: 'StringParameterValue', name: 'version', value: version],
]
build job: 'marathon-deploy-app', parameters: [
[$class: 'StringParameterValue', name: 'app', value: 'ocfweb/static'],
[$class: 'StringParameterValue', name: 'version', value: version],
]
}
}
}
}
} catch (err) {
def subject = "${env.JOB_NAME} - Build #${env.BUILD_NUMBER} - Failure!"
def message = "${env.JOB_NAME} (#${env.BUILD_NUMBER}) failed: ${env.BUILD_URL}"
if (env.BRANCH_NAME == 'master') {
slackSend color: '#FF0000', message: message
mail to: '[email protected]', subject: subject, body: message
} else {
mail to: emailextrecipients([
[$class: 'CulpritsRecipientProvider'],
[$class: 'DevelopersRecipientProvider']
]), subject: subject, body: message
}
throw err
}
// vim: ft=groovy