forked from cryoem/eman2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
202 lines (171 loc) · 5.21 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
191
192
193
194
195
196
197
198
199
200
201
202
def getJobType() {
def causes = "${currentBuild.rawBuild.getCauses()}"
def job_type = "UNKNOWN"
if(causes ==~ /.*TimerTrigger.*/) { job_type = "cron" }
if(causes ==~ /.*GitHubPushCause.*/) { job_type = "push" }
if(causes ==~ /.*UserIdCause.*/) { job_type = "manual" }
if(causes ==~ /.*ReplayCause.*/) { job_type = "manual" }
return job_type
}
def notifyGitHub(status) {
if(JOB_TYPE == "push") {
if(status == 'PENDING') { message = 'Building...' }
if(status == 'SUCCESS') { message = 'Build succeeded!' }
if(status == 'FAILURE') { message = 'Build failed!' }
if(status == 'ERROR') { message = 'Build aborted!' }
step([$class: 'GitHubCommitStatusSetter', contextSource: [$class: 'ManuallyEnteredCommitContextSource', context: "JenkinsCI/${JOB_NAME}"], statusResultSource: [$class: 'ConditionalStatusResultSource', results: [[$class: 'AnyBuildResult', message: message, state: status]]]])
}
}
def notifyEmail() {
if(JOB_TYPE == "push") {
emailext(recipientProviders: [[$class: 'DevelopersRecipientProvider']],
subject: '[JenkinsCI/$PROJECT_NAME/push] ' + "($GIT_BRANCH_SHORT - ${GIT_COMMIT_SHORT})" + ' #$BUILD_NUMBER - $BUILD_STATUS!',
body: '''${SCRIPT, template="groovy-text.template"}''',
attachLog: true
)
}
if(JOB_TYPE == "cron") {
emailext(to: '$DEFAULT_RECIPIENTS',
subject: '[JenkinsCI/$PROJECT_NAME/cron] ' + "($GIT_BRANCH_SHORT - ${GIT_COMMIT_SHORT})" + ' #$BUILD_NUMBER - $BUILD_STATUS!',
body: '''${SCRIPT, template="groovy-text.template"}''',
attachLog: true
)
}
}
def isRelease() {
return (GIT_BRANCH ==~ /.*\/release.*/) && (JOB_TYPE == "push")
}
def isContinuousBuild() {
return (GIT_BRANCH ==~ /origin\/master/)
}
def runCronJob() {
sh "bash ${HOME}/workspace/build-scripts-cron/cronjob.sh $STAGE_NAME $GIT_BRANCH_SHORT"
if(isContinuousBuild())
sh "rsync -avzh --stats ${INSTALLERS_DIR}/eman2.${STAGE_NAME}.unstable.sh ${DEPLOY_DEST}"
}
def setUploadFlag() {
if(isContinuousBuild()) {
return '0'
} else {
return '1'
}
}
def resetBuildScripts() {
if(isContinuousBuild() || isRelease())
sh 'cd ${HOME}/workspace/build-scripts-cron/ && git checkout -f master'
}
pipeline {
agent {
node { label 'jenkins-slave-1' }
}
options { disableConcurrentBuilds() }
triggers {
cron('0 3 * * *')
}
environment {
SKIP_UPLOAD = setUploadFlag()
JOB_TYPE = getJobType()
GIT_BRANCH_SHORT = sh(returnStdout: true, script: 'echo ${GIT_BRANCH##origin/}').trim()
GIT_COMMIT_SHORT = sh(returnStdout: true, script: 'echo ${GIT_COMMIT:0:7}').trim()
INSTALLERS_DIR = '${HOME}/workspace/${STAGE_NAME}-installers'
DEPLOY_DEST = '[email protected]:/home/zope/zope-server/extdata/reposit/ncmi/software/counter_222/software_136/'
NUMPY_VERSION='1.9'
BUILD_SCRIPTS_BRANCH='master'
}
stages {
// Stages triggered by GitHub pushes
stage('notify-pending') {
when {
expression { JOB_TYPE == "push" }
}
steps {
notifyGitHub('PENDING')
}
}
stage('build') {
when {
not { expression { JOB_TYPE == "cron" } }
not { expression { isRelease() } }
not { expression { isContinuousBuild() } }
}
parallel {
stage('recipe') {
steps {
sh 'bash ci_support/build_recipe.sh'
}
}
stage('no_recipe') {
steps {
sh 'source $(conda info --root)/bin/activate eman-env && bash ci_support/build_no_recipe.sh'
}
}
}
}
// Stages triggered by cron or by a release branch
stage('build-scripts-checkout') {
when {
anyOf {
expression { isContinuousBuild() }
expression { isRelease() }
}
}
steps {
sh 'cd ${HOME}/workspace/build-scripts-cron/ && git fetch --prune && (git checkout -f $BUILD_SCRIPTS_BRANCH || git checkout -t origin/$BUILD_SCRIPTS_BRANCH) && git pull --rebase'
}
}
stage('centos6') {
when {
anyOf {
expression { isContinuousBuild() }
expression { isRelease() }
}
expression { SLAVE_OS == "linux" }
}
steps {
runCronJob()
}
}
stage('centos7') {
when {
anyOf {
expression { isContinuousBuild() }
expression { isRelease() }
}
expression { SLAVE_OS == "linux" }
}
steps {
runCronJob()
}
}
stage('mac') {
when {
anyOf {
expression { isContinuousBuild() }
expression { isRelease() }
}
expression { SLAVE_OS == "mac" }
}
environment {
EMAN_TEST_SKIP=1
}
steps {
runCronJob()
}
}
}
post {
success {
notifyGitHub('SUCCESS')
}
failure {
notifyGitHub('FAILURE')
}
aborted {
notifyGitHub('ERROR')
}
always {
notifyEmail()
resetBuildScripts()
}
}
}