forked from apache/maven
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
157 lines (144 loc) · 6.34 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
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
properties([buildDiscarder(logRotator(artifactNumToKeepStr: '5', numToKeepStr: env.BRANCH_NAME=='master'?'5':'1'))])
def buildOs = 'linux'
def buildJdk = '8'
def buildMvn = '3.6.0'
def runITsOses = ['linux', 'windows']
def runITsJdks = ['7', '8', '11','12']
def runITsMvn = '3.6.0'
def runITscommand = "mvn clean install -Prun-its,embedded -B -U -V" // -DmavenDistro=... -Dmaven.test.failure.ignore=true
def tests
try {
def osNode = jenkinsEnv.labelForOS(buildOs)
node(jenkinsEnv.nodeSelection(osNode)) {
dir('build') {
stage('Checkout') {
checkout scm
}
def WORK_DIR=pwd()
def MAVEN_GOAL='verify'
stage('Configure deploy') {
if (env.BRANCH_NAME == 'master'){
MAVEN_GOAL='deploy'
}
}
stage('Build / Unit Test') {
String jdkName = jenkinsEnv.jdkFromVersion(buildOs, buildJdk)
String mvnName = jenkinsEnv.mvnFromVersion(buildOs, buildMvn)
withMaven(jdk: jdkName, maven: mvnName, mavenLocalRepo:"${WORK_DIR}/.repository", options:[
artifactsPublisher(disabled: false),
junitPublisher(ignoreAttachments: false),
findbugsPublisher(disabled: false),
openTasksPublisher(disabled: false),
dependenciesFingerprintPublisher(),
invokerPublisher(),
pipelineGraphPublisher()
]) {
sh "mvn clean ${MAVEN_GOAL} -B -U -e -fae -V -Dmaven.test.failure.ignore=true"
}
dir ('apache-maven/target') {
sh "mv apache-maven-*-bin.zip apache-maven-dist.zip"
stash includes: 'apache-maven-dist.zip', name: 'dist'
}
}
tests = resolveScm source: [$class: 'GitSCMSource', credentialsId: '', id: '_', remote: 'https://gitbox.apache.org/repos/asf/maven-integration-testing.git', traits: [[$class: 'jenkins.plugins.git.traits.BranchDiscoveryTrait'], [$class: 'GitToolSCMSourceTrait', gitTool: 'Default']]], targets: [BRANCH_NAME, 'master']
}
}
Map runITsTasks = [:]
for (String os in runITsOses) {
for (def jdk in runITsJdks) {
String osLabel = jenkinsEnv.labelForOS(os);
String jdkName = jenkinsEnv.jdkFromVersion(os, "${jdk}")
String mvnName = jenkinsEnv.mvnFromVersion(os, "${runITsMvn}")
echo "OS: ${os} JDK: ${jdk} => Label: ${osLabel} JDK: ${jdkName}"
String stageId = "${os}-jdk${jdk}"
String stageLabel = "Run ITs ${os.capitalize()} Java ${jdk}"
runITsTasks[stageId] = {
node(jenkinsEnv.nodeSelection(osLabel)) {
stage("${stageLabel}") {
// on Windows, need a short path or we hit 256 character limit for paths
// using EXECUTOR_NUMBER guarantees that concurrent builds on same agent
// will not trample each other plus workaround for JENKINS-52657
dir(isUnix() ? 'test' : "c:\\mvn-it-${EXECUTOR_NUMBER}.tmp") {
def WORK_DIR=pwd()
checkout tests
if (isUnix()) {
sh "rm -rvf $WORK_DIR/apache-maven-dist.zip $WORK_DIR/it-local-repo"
} else {
bat "if exist it-local-repo rmdir /s /q it-local-repo"
bat "if exist apache-maven-dist.zip del /q apache-maven-dist.zip"
}
unstash 'dist'
withMaven(jdk: jdkName, maven: mvnName, mavenLocalRepo:"${WORK_DIR}/it-local-repo", options:[
junitPublisher(ignoreAttachments: false)
]) {
String cmd = "${runITscommand} -DmavenDistro=$WORK_DIR/apache-maven-dist.zip -Dmaven.test.failure.ignore=true"
if (stageId.endsWith('-jdk7')) {
// Java 7u80 has TLS 1.2 disabled by default: need to explicitly enable
cmd = "${cmd} -Dhttps.protocols=TLSv1.2"
}
if (isUnix()) {
sh "${cmd}"
} else {
bat "${cmd}"
}
}
deleteDir() // clean up after ourselves to reduce disk space
}
}
}
}
}
}
// run the parallel ITs
parallel(runITsTasks)
// JENKINS-34376 seems to make it hard to detect the aborted builds
} catch (org.jenkinsci.plugins.workflow.steps.FlowInterruptedException e) {
echo "[FAILURE-002] FlowInterruptedException ${e}"
// this ambiguous condition means a user probably aborted
if (e.causes.size() == 0) {
currentBuild.result = "ABORTED"
} else {
currentBuild.result = "FAILURE"
}
throw e
} catch (hudson.AbortException e) {
echo "[FAILURE-003] AbortException ${e}"
// this ambiguous condition means during a shell step, user probably aborted
if (e.getMessage().contains('script returned exit code 143')) {
currentBuild.result = "ABORTED"
} else {
currentBuild.result = "FAILURE"
}
throw e
} catch (InterruptedException e) {
echo "[FAILURE-004] ${e}"
currentBuild.result = "ABORTED"
throw e
} catch (Throwable e) {
echo "[FAILURE-001] ${e}"
currentBuild.result = "FAILURE"
throw e
} finally {
// notify completion
stage("Notifications") {
jenkinsNotify()
}
}