forked from devonfw/cobigen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
270 lines (242 loc) · 11.4 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
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
properties([
parameters([
string(name: 'TRIGGER_SHA', defaultValue: '', description: 'The sha of the commit that triggered the calling job'),
string(name: 'TRIGGER_REPO', defaultValue: '', description: 'The URI of the commit that triggered the calling job')
]),
[$class: 'BuildDiscarderProperty', strategy: [$class: 'LogRotator', artifactDaysToKeepStr: '', artifactNumToKeepStr: '', daysToKeepStr: '', numToKeepStr: '10']]
])
node {
//lock(resource: "pipeline_${env.NODE_NAME}_${env.JOB_NAME}", inversePrecedence: false) {
try {
stage('prepare') {
step([$class: 'WsCleanup'])
}
// will hold the current branch name
def origin_branch =""
stage('setting up environment & cloning repositories') {
checkout scm
// CHANGE_TARGET seems only to be set at PR- build jobs. Since there is (seemingly) no documentation the variable is used if it is present. Otherwise BRANCH_NAME is used that fits on normal branch builds
if(env.CHANGE_TARGET != null){
origin_branch = env.CHANGE_TARGET
echo 'using CHANGE_TARGET as branch name: '+origin_branch
}else{
origin_branch=env.BRANCH_NAME
echo 'using BRANCH_NAME as branch name: '+origin_branch
}
env.GIT_COMMIT = sh(script: "git rev-parse HEAD", returnStdout: true).trim()
setBuildStatus("In Progress","PENDING")
// Tools have to be configured in the global configuration of Jenkins.
env.MAVEN_HOME="${tool 'Maven 3.5.4'}"
env.M2_HOME="${env.MAVEN_HOME}" // for recognition by maven invoker (test utility)
env.JAVA_HOME="${tool 'Java8'}"
env.PATH="${env.MAVEN_HOME}/bin:${env.JAVA_HOME}/bin:${env.PATH}"
// load VNC Server for eclipse tests
tool 'VNC Server'
}
def non_deployable_branches = ["master","gh-pages","dev_eclipseplugin","dev_oomph_setup"]
def root = ""
if (origin_branch == "master") {
if(justOneFolderChanged("cobigen-templates/")) {
echo "Just Templates changed!"
root = "cobigen-templates"
} else if(justOneFolderChanged("cobigen-cli/")) {
root = "cobigen-cli"
} else {
root = ""
}
} else if (origin_branch == "dev_eclipseplugin") {
root = "cobigen-eclipse"
} else if (origin_branch == "dev_htmlmerger") {
root = "cobigen/cobigen-htmlplugin"
} else if (origin_branch == "dev_mavenplugin") {
root = "cobigen-maven"
} else if (origin_branch == "dev_tempeng_freemarker") {
root = "cobigen/cobigen-templateengines/cobigen-tempeng-freemarker"
} else if (origin_branch == "dev_tempeng_velocity") {
root = "cobigen/cobigen-templateengines/cobigen-tempeng-velocity"
} else if (origin_branch == "dev_core") {
root = "cobigen/cobigen-core-parent"
} else if (origin_branch == "dev_javaplugin") {
root = "cobigen/cobigen-javaplugin-parent"
} else if (origin_branch == "dev_openapiplugin") {
root = "cobigen/cobigen-openapiplugin-parent"
} else if (origin_branch == "gh-pages" || origin_branch == "dev_oomph_setup") {
currentBuild.result = 'SUCCESS'
setBuildStatus("Complete","SUCCESS")
sh "exit 0"
} else {
root = "cobigen/cobigen-" + origin_branch.replace("dev_", "")
}
stage('build & test') {
dir(root) {
withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: 'pl-technical-user', usernameVariable: 'DEVON_NEXUS_USER', passwordVariable: 'DEVON_NEXUS_PASSWD']]) {
// load jenkins managed global maven settings file
configFileProvider([configFile(fileId: '9d437f6e-46e7-4a11-a8d1-2f0055f14033', variable: 'MAVEN_SETTINGS')]) {
try {
if(origin_branch == 'master') {
// https://github.com/jenkinsci/xvnc-plugin/blob/master/src/main/java/hudson/plugins/xvnc/Xvnc.java
wrap([$class:'Xvnc', useXauthority: true]) { // takeScreenshot: true, causes issues seemingly
sh 'export SWT_GTK3=0' // disable GTK3 as of linux bug (see also https://bbs.archlinux.org/viewtopic.php?id=218587)
sh "mvn -s ${MAVEN_SETTINGS} clean install -U -Pp2-build-photon,p2-build-stable"
}
} else if (origin_branch == 'dev_eclipseplugin') {
sh "mvn -s ${MAVEN_SETTINGS} clean package -U -Pp2-build-photon,p2-build-ci"
} else {
sh "mvn -s ${MAVEN_SETTINGS} clean install -U"
}
} catch(err) {
step([$class: 'JUnitResultArchiver', testResults: '**/target/surefire-reports/*.xml', allowEmptyResults: false])
if (currentBuild.result != 'UNSTABLE') { // JUnitResultArchiver sets result to UNSTABLE. If so, indicate UNSTABLE, otherwise throw error.
throw err
}
}
}
}
}
}
if (currentBuild.result == 'UNSTABLE') {
setBuildStatus("Complete","FAILURE")
notifyFailed()
return // do the return outside of stage area to exit the pipeline
}
stage('process test results') {
// added 'allowEmptyResults:true' to prevent failure in case of no tests
step([$class: 'JUnitResultArchiver', testResults: '**/target/surefire-reports/*.xml', allowEmptyResults: true])
}
if (currentBuild.result == 'UNSTABLE') {
setBuildStatus("Complete","FAILURE")
notifyFailed()
return
}
stage('deploy') {
dir(root) {
configFileProvider([configFile(fileId: '9d437f6e-46e7-4a11-a8d1-2f0055f14033', variable: 'MAVEN_SETTINGS')]) {
if (!non_deployable_branches.contains(origin_branch)) {
sh "mvn -s ${MAVEN_SETTINGS} deploy -U -Dmaven.test.skip=true"
if (origin_branch != 'dev_core' && origin_branch != 'dev_mavenplugin'){
def deployRoot = ""
if(origin_branch == 'dev_javaplugin'){
deployRoot = "cobigen-javaplugin"
}
if(origin_branch == 'dev_openapiplugin'){
deployRoot = "cobigen-openapiplugin"
}
dir(deployRoot) {
// we currently need these three steps to assure the correct sequence of packaging,
// manifest extension, osgi bundling, and upload
sh "mvn -s ${MAVEN_SETTINGS} package -U bundle:bundle -Pp2-bundle,p2-build-photon,p2-build-ci -Dmaven.test.skip=true"
sh "mvn -s ${MAVEN_SETTINGS} install -U bundle:bundle -Pp2-bundle,p2-build-photon,p2-build-ci p2:site -Dmaven.test.skip=true"
sh "mvn -s ${MAVEN_SETTINGS} deploy -U -Pp2-build-photon,p2-build-ci -Dmaven.test.skip=true -Dp2.upload=ci"
}
if(origin_branch == "dev_javaplugin"){
dir("cobigen-javaplugin-model"){
sh "mvn -s ${MAVEN_SETTINGS} deploy -U -Dmaven.test.skip=true"
}
}
if(origin_branch == "dev_openapiplugin"){
dir("cobigen-openapiplugin-model"){
sh "mvn -s ${MAVEN_SETTINGS} deploy -Dmaven.test.skip=true"
}
}
}
} else if(origin_branch == 'dev_eclipseplugin') {
withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: 'fileserver', usernameVariable: 'ICSD_FILESERVER_USER', passwordVariable: 'ICSD_FILESERVER_PASSWD']]) {
sh "mvn -s ${MAVEN_SETTINGS} deploy -U -Dmaven.test.skip=true -Pp2-build-photon,p2-build-ci -Dp2.upload=ci"
}
}
}
}
}
if(origin_branch == 'dev_eclipseplugin') {
stage('integration test') {
dir(root) {
// https://github.com/jenkinsci/xvnc-plugin/blob/master/src/main/java/hudson/plugins/xvnc/Xvnc.java
wrap([$class:'Xvnc', useXauthority: true]) { // takeScreenshot: true, causes issues seemingly
withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: 'pl-technical-user', usernameVariable: 'DEVON_NEXUS_USER', passwordVariable: 'DEVON_NEXUS_PASSWD']]) {
// load jenkins managed global maven settings file
configFileProvider([configFile(fileId: '9d437f6e-46e7-4a11-a8d1-2f0055f14033', variable: 'MAVEN_SETTINGS')]) {
try {
sh 'export SWT_GTK3=0' // disable GTK3 as of linux bug (see also https://bbs.archlinux.org/viewtopic.php?id=218587)
sh "mvn -s ${MAVEN_SETTINGS} integration-test -Pp2-build-photon,p2-build-ci"
} catch(err) {
step([$class: 'JUnitResultArchiver', testResults: '**/target/surefire-reports/*.xml', allowEmptyResults: false])
if (currentBuild.result != 'UNSTABLE') { // JUnitResultArchiver sets result to UNSTABLE. If so, indicate UNSTABLE, otherwise throw error.
throw err
}
}
}
}
}
}
}
}
if (currentBuild.result == 'UNSTABLE') {
setBuildStatus("Complete","FAILURE")
notifyFailed()
return // do the return outside of stage area to exit the pipeline
}
stage('process test results') {
// added 'allowEmptyResults:true' to prevent failure in case of no tests
step([$class: 'JUnitResultArchiver', testResults: '**/target/surefire-reports/*.xml', allowEmptyResults: true])
archiveArtifacts artifacts: '**/target/screenshots/*.jpeg', allowEmptyArchive: true
}
// triggering of upcoming builds
if(origin_branch != 'dev_eclipseplugin' && origin_branch != 'dev_mavenplugin' && origin_branch != 'master'){
stage('integration-test') {
def repo = sh(script: "git config --get remote.origin.url", returnStdout: true).trim()
build job: 'dev_eclipseplugin', wait: false, parameters: [[$class:'StringParameterValue', name:'TRIGGER_SHA', value:env.GIT_COMMIT], [$class:'StringParameterValue', name:'TRIGGER_REPO', value: repo]]
build job: 'dev_mavenplugin', wait: false, parameters: [[$class:'StringParameterValue', name:'TRIGGER_SHA', value:env.GIT_COMMIT], [$class:'StringParameterValue', name:'TRIGGER_REPO', value: repo]]
}
}
} catch(e) {
if (currentBuild.result != 'UNSTABLE') {
currentBuild.result = 'FAILURE'
setBuildStatus("Incomplete","ERROR")
}
notifyFailed()
stage('clean up') {
cleanWs()
deleteDir()
}
throw e
}
setBuildStatus("Complete","SUCCESS")
//}
stage('clean up') {
cleanWs()
deleteDir()
}
}
def isPRBuild() {
return (env.BRANCH_NAME ==~ /^PR-\d+$/)
}
def justOneFolderChanged(String folderName) {
// split will return a list with one element (the empty string) if called on an empty string
diff_files= sh(script: "git diff --name-only origin/master | xargs", returnStdout: true).trim().split("\\s+")
for(int i=0; i < diff_files.size(); i++) {
if(!diff_files[i].startsWith(folderName)) {
echo "'${diff_files[i]}' does not start with /" + folderName
return false
}
}
return true
}
def notifyFailed() {
emailext(body: '${DEFAULT_CONTENT}', mimeType: 'text/html',
replyTo: '$DEFAULT_REPLYTO', subject: '${DEFAULT_SUBJECT}',
to: emailextrecipients([[$class: 'CulpritsRecipientProvider'],
[$class: 'RequesterRecipientProvider'],
[$class: 'DevelopersRecipientProvider'],
[$class: 'FailingTestSuspectsRecipientProvider'],
[$class: 'UpstreamComitterRecipientProvider']]))
}
def setBuildStatus(String message, String state) {
try{
if(env.TRIGGER_SHA != null && env.TRIGGER_SHA != '' && env.TRIGGER_REPO != null && TRIGGER_REPO != '') {
step([$class: 'GitHubCommitStatusSetter', commitShaSource: [$class:'ManuallyEnteredShaSource', sha:env.TRIGGER], reposSource: [$class:'ManuallyEnteredRepositorySource', url:env.TRIGGER_REPO], contextSource: [$class: 'ManuallyEnteredCommitContextSource', context: "integration-test"], statusResultSource: [$class: 'ConditionalStatusResultSource', results: [[$class: 'AnyBuildResult', message: message, state: state]]]])
}
} catch(e) {
echo "Could not set build status for ${params.TRIGGER}: ${message}, ${state}"
echo "Exception ${e.toString()}:${e.getMessage()}"
}
}