forked from cryoem/eman2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
187 lines (155 loc) · 4.66 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
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(to: "$GIT_AUTHOR_EMAIL",
subject: '[JenkinsCI/$PROJECT_NAME] ' + "($GIT_BRANCH_SHORT - ${GIT_COMMIT_SHORT})" + ' #$BUILD_NUMBER - $BUILD_STATUS!',
body: '''${SCRIPT, template="groovy-text.template"}''',
attachLog: true
)
}
}
def isMasterBranch() {
return GIT_BRANCH_SHORT == "master"
}
def isReleaseBranch() {
return GIT_BRANCH_SHORT ==~ /release.*/
}
def isContinuousBuild() {
return (CI_BUILD == "1" && isMasterBranch()) || isReleaseBranch()
}
def isExperimentalBuild() {
return CI_BUILD == "1" && !(isMasterBranch() || isReleaseBranch())
}
def isBinaryBuild() {
return isContinuousBuild() || isExperimentalBuild()
}
def testPackage() {
if(SLAVE_OS != 'win')
sh "bash tests/test_binary_installation.sh ${INSTALLERS_DIR} eman2.${SLAVE_OS}.sh"
else
sh 'ci_support/test_wrapper.sh'
}
def deployPackage() {
if(isContinuousBuild()) {
upload_dir = 'continuous_build'
upload_ext = 'unstable'
}
if(isExperimentalBuild()) {
upload_dir = 'experimental'
upload_ext = 'experimental'
}
if(SLAVE_OS != 'win')
sh "rsync -avzh --stats ${INSTALLERS_DIR}/eman2.${SLAVE_OS}.sh ${DEPLOY_DEST}/" + upload_dir + "/eman2." + JOB_NAME.toLowerCase() + "." + upload_ext + ".sh"
else
bat 'ci_support\\rsync_wrapper.bat ' + upload_dir + ' ' + upload_ext
}
def getHomeDir() {
def result = ''
if(SLAVE_OS == "win") {
result = "${USERPROFILE}"
}
else {
result = "${HOME}"
}
return result
}
pipeline {
agent {
node { label "${JOB_NAME}-slave" }
}
options {
disableConcurrentBuilds()
timestamps()
}
environment {
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()
GIT_AUTHOR_EMAIL = sh(returnStdout: true, script: 'git log -1 --format="%ae"').trim()
HOME_DIR = getHomeDir()
HOME = "${HOME_DIR}" // on Windows HOME is set to something like C:\Program Files\home\eman
INSTALLERS_DIR = '${HOME_DIR}/workspace/${JOB_NAME}-installers'
CI_BUILD = sh(script: "! git log -1 | grep '.*\\[ci build\\].*'", returnStatus: true)
}
stages {
// Stages triggered by GitHub pushes
stage('notify-pending') {
steps {
notifyGitHub('PENDING')
sh 'env | sort'
}
}
stage('build-local') {
when {
not { expression { isBinaryBuild() } }
expression { JOB_NAME != 'Win' }
}
steps {
sh 'source $(conda info --root)/bin/activate eman-deps-13.0 && bash ci_support/build_no_recipe.sh'
}
}
stage('build-recipe') {
steps {
sh 'bash ci_support/build_recipe.sh'
}
}
stage('package') {
when {
expression { isBinaryBuild() }
}
steps {
sh "bash ci_support/package.sh ${INSTALLERS_DIR} " + '${WORKSPACE}/ci_support/'
}
}
stage('test-package') {
when {
expression {isBinaryBuild() }
}
steps {
testPackage()
}
}
stage('deploy') {
when {
expression {isBinaryBuild() }
}
steps {
deployPackage()
}
}
}
post {
success {
notifyGitHub('SUCCESS')
}
failure {
notifyGitHub('FAILURE')
}
aborted {
notifyGitHub('ERROR')
}
always {
notifyEmail()
}
}
}