Skip to content

Commit 358397b

Browse files
authored
Merge pull request #299 from apache/jenkins-matrix-1.8
(build) jenkins matrix 1.8
2 parents efa5654 + a9f646d commit 358397b

File tree

4 files changed

+186
-519
lines changed

4 files changed

+186
-519
lines changed

.jenkins.groovy

Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
def deployableBranch = env.BRANCH_NAME ==~ /(1.7.x|1.8.x|main)/
21+
22+
pipeline {
23+
24+
agent none
25+
26+
options {
27+
// When we have test-fails e.g. we don't need to run the remaining steps
28+
skipStagesAfterUnstable()
29+
buildDiscarder(logRotator(numToKeepStr: '5', artifactNumToKeepStr: '5'))
30+
}
31+
32+
stages {
33+
stage('Build') {
34+
matrix {
35+
axes {
36+
axis {
37+
// https://cwiki.apache.org/confluence/display/INFRA/JDK+Installation+Matrix
38+
name 'MATRIX_JDK'
39+
values 'jdk_1.8_latest',
40+
'jdk_11_latest',
41+
'jdk_14_latest'
42+
}
43+
// Additional axess, like OS and maven version can be configured here.
44+
}
45+
46+
agent {
47+
node {
48+
// https://cwiki.apache.org/confluence/display/INFRA/ci-builds.apache.org
49+
label 'ubuntu'
50+
}
51+
}
52+
53+
options {
54+
// Configure an overall timeout for the build of one hour.
55+
timeout(time: 1, unit: 'HOURS')
56+
}
57+
58+
tools {
59+
// https://cwiki.apache.org/confluence/display/INFRA/Maven+Installation+Matrix
60+
maven 'maven_3_latest'
61+
jdk "${MATRIX_JDK}"
62+
}
63+
64+
stages {
65+
stage('Initialization') {
66+
steps {
67+
echo 'Building Branch: ' + env.BRANCH_NAME
68+
echo 'Using PATH = ' + env.PATH
69+
}
70+
}
71+
72+
stage('Cleanup') {
73+
steps {
74+
echo 'Cleaning up the workspace'
75+
cleanWs()
76+
}
77+
}
78+
79+
stage('Checkout') {
80+
steps {
81+
echo 'Checking out branch ' + env.BRANCH_NAME
82+
checkout scm
83+
}
84+
}
85+
86+
stage('License check') {
87+
steps {
88+
echo 'License check'
89+
sh 'mvn --batch-mode -Drat.consoleOutput=true apache-rat:check'
90+
}
91+
}
92+
93+
stage('Build') {
94+
steps {
95+
echo 'Building'
96+
sh 'mvn --batch-mode --errors clean verify -Pdocs -Dmaven.test.failure.ignore=true'
97+
}
98+
post {
99+
always {
100+
junit(testResults: '**/surefire-reports/*.xml', allowEmptyResults: true)
101+
junit(testResults: '**/failsafe-reports/*.xml', allowEmptyResults: true)
102+
}
103+
}
104+
}
105+
106+
stage('Deploy') {
107+
when {
108+
allOf {
109+
expression { deployableBranch }
110+
expression { MATRIX_JDK == 'jdk_11_latest' }
111+
// is not a PR (GitHub) / MergeRequest (GitLab) / Change (Gerrit)?
112+
not { changeRequest() }
113+
}
114+
}
115+
steps {
116+
echo 'Deploying'
117+
sh 'mvn --batch-mode clean deploy -Pdocs -DskipTests'
118+
}
119+
}
120+
121+
} // end of stages
122+
123+
// Do any post build stuff ... such as sending emails depending on the overall build result.
124+
post {
125+
// If this build failed, send an email to the list.
126+
failure {
127+
script {
128+
if (deployableBranch) {
129+
emailext(
130+
subject: "[BUILD-FAILURE]: Job '${env.JOB_NAME} [${env.BRANCH_NAME}] [${env.BUILD_NUMBER}]'",
131+
body: """
132+
BUILD-FAILURE: Job '${env.JOB_NAME} [${env.BRANCH_NAME}] [${env.BUILD_NUMBER}]':
133+
Check console output at "<a href="${env.BUILD_URL}">${env.JOB_NAME} [${env.BRANCH_NAME}] [${env.BUILD_NUMBER}]</a>"
134+
""",
135+
136+
recipientProviders: [[$class: 'DevelopersRecipientProvider']]
137+
)
138+
}
139+
}
140+
}
141+
142+
// If this build didn't fail, but there were failing tests, send an email to the list.
143+
unstable {
144+
script {
145+
if (deployableBranch) {
146+
emailext(
147+
subject: "[BUILD-UNSTABLE]: Job '${env.JOB_NAME} [${env.BRANCH_NAME}] [${env.BUILD_NUMBER}]'",
148+
body: """
149+
BUILD-UNSTABLE: Job '${env.JOB_NAME} [${env.BRANCH_NAME}] [${env.BUILD_NUMBER}]':
150+
Check console output at "<a href="${env.BUILD_URL}">${env.JOB_NAME} [${env.BRANCH_NAME}] [${env.BUILD_NUMBER}]</a>"
151+
""",
152+
153+
recipientProviders: [[$class: 'DevelopersRecipientProvider']]
154+
)
155+
}
156+
}
157+
}
158+
159+
// Send an email, if the last build was not successful and this one is.
160+
success {
161+
// Cleanup the build directory if the build was successful
162+
// (in this cae we probably don't have to do any post-build analysis)
163+
cleanWs()
164+
script {
165+
if (deployableBranch
166+
&& (currentBuild.previousBuild != null) && (currentBuild.previousBuild.result != 'SUCCESS')) {
167+
emailext(
168+
subject: "[BUILD-STABLE]: Job '${env.JOB_NAME} [${env.BRANCH_NAME}] [${env.BUILD_NUMBER}]'",
169+
body: """
170+
BUILD-STABLE: Job '${env.JOB_NAME} [${env.BRANCH_NAME}] [${env.BUILD_NUMBER}]':
171+
Is back to normal.
172+
""",
173+
174+
recipientProviders: [[$class: 'DevelopersRecipientProvider']]
175+
)
176+
}
177+
}
178+
}
179+
} // end of post
180+
181+
} // end of matrix
182+
183+
} // main stage ('Build')
184+
185+
} // main stages
186+
}

Jenkinsfile

Lines changed: 0 additions & 181 deletions
This file was deleted.

0 commit comments

Comments
 (0)