|
| 1 | +def configurations = [ |
| 2 | + [ platform: "linux", jdk: "11" ] |
| 3 | +] |
1 | 4 |
|
2 | | - Map params = [:] |
3 | | - |
4 | | - // Faster build and reduces IO needs |
5 | | - properties([ |
6 | | - durabilityHint('PERFORMANCE_OPTIMIZED'), |
7 | | - buildDiscarder(logRotator(numToKeepStr: '5')), |
8 | | - ]) |
9 | | - |
10 | | - def repo = params.containsKey('repo') ? params.repo : null |
11 | | - def failFast = params.containsKey('failFast') ? params.failFast : true |
12 | | - def timeoutValue = params.containsKey('timeout') ? params.timeout : 60 |
13 | | - def useAci = params.containsKey('useAci') ? params.useAci : false |
14 | | - def forceAci = params.containsKey('forceAci') ? params.forceAci : false |
15 | | - if(timeoutValue > 180) { |
16 | | - echo "Timeout value requested was $timeoutValue, lowering to 180 to avoid Jenkins project's resource abusive consumption" |
17 | | - timeoutValue = 180 |
18 | | - } |
19 | | - |
20 | | - boolean publishingIncrementals = false |
21 | | - boolean archivedArtifacts = false |
22 | | - Map tasks = [failFast: failFast] |
23 | | - getConfigurations(params).each { config -> |
24 | | - String label = config.platform |
25 | | - String jdk = config.jdk |
26 | | - String jenkinsVersion = config.jenkins |
27 | | - String javaLevel = config.javaLevel |
28 | | - |
29 | | - String stageIdentifier = "${label}-${jdk}${jenkinsVersion ? '-' + jenkinsVersion : ''}" |
30 | | - boolean first = tasks.size() == 1 |
31 | | - boolean skipTests = params?.tests?.skip |
32 | | - boolean addToolEnv = !useAci |
33 | | - |
34 | | - if(useAci && (label == 'linux' || label == 'windows')) { |
35 | | - String aciLabel = jdk == '8' ? 'maven' : 'maven-11' |
36 | | - if(label == 'windows') { |
37 | | - aciLabel += "-windows" |
38 | | - } |
39 | | - label = aciLabel |
40 | | - } |
41 | | - |
42 | | - tasks[stageIdentifier] = { |
43 | | - node(label) { |
44 | | - try { |
45 | | - timeout(timeoutValue) { |
46 | | - boolean isMaven |
47 | | - // Archive artifacts once with pom declared baseline |
48 | | - boolean doArchiveArtifacts = !jenkinsVersion && !archivedArtifacts |
49 | | - if (doArchiveArtifacts) { |
50 | | - archivedArtifacts = true |
51 | | - } |
52 | | - boolean incrementals // cf. JEP-305 |
53 | | - |
54 | | - stage("Checkout (${stageIdentifier})") { |
55 | | - infra.checkout(repo) |
56 | | - isMaven = fileExists('pom.xml') |
57 | | - incrementals = fileExists('.mvn/extensions.xml') && |
58 | | - readFile('.mvn/extensions.xml').contains('git-changelist-maven-extension') |
59 | | - } |
60 | | - |
61 | | - String changelistF |
62 | | - String m2repo |
63 | | - |
64 | | - stage("Build (${stageIdentifier})") { |
65 | | - String command |
66 | | - if (isMaven) { |
67 | | - m2repo = "${pwd tmp: true}/m2repo" |
68 | | - List<String> mavenOptions = [ |
69 | | - '--update-snapshots', |
70 | | - "-Dmaven.repo.local=$m2repo", |
71 | | - '-Dmaven.test.failure.ignore', |
72 | | - ] |
73 | | - if (incrementals) { // set changelist and activate produce-incrementals profile |
74 | | - mavenOptions += '-Dset.changelist' |
75 | | - if (doArchiveArtifacts) { // ask Maven for the value of -rc999.abc123def456 |
76 | | - changelistF = "${pwd tmp: true}/changelist" |
77 | | - mavenOptions += "help:evaluate -Dexpression=changelist -Doutput=$changelistF" |
78 | | - } |
79 | | - } |
80 | | - if (jenkinsVersion) { |
81 | | - mavenOptions += "-Djenkins.version=${jenkinsVersion} -Daccess-modifier-checker.failOnError=false" |
82 | | - } |
83 | | - if (javaLevel) { |
84 | | - mavenOptions += "-Djava.level=${javaLevel}" |
85 | | - } |
86 | | - if (skipTests) { |
87 | | - mavenOptions += "-DskipTests -DskipITs" |
88 | | - } |
89 | | - mavenOptions += "clean install" |
90 | | - infra.runMaven(mavenOptions, jdk, null, null, addToolEnv) |
91 | | - } else { |
92 | | - echo "WARNING: Gradle mode for buildPlugin() is deprecated, please use buildPluginWithGradle()" |
93 | | - List<String> gradleOptions = [ |
94 | | - '--no-daemon', |
95 | | - 'cleanTest', |
96 | | - 'build', |
97 | | - ] |
98 | | - command = "gradlew ${gradleOptions.join(' ')}" |
99 | | - if (isUnix()) { |
100 | | - command = "./" + command |
101 | | - } |
102 | | - infra.runWithJava(command, jdk, null, addToolEnv) |
103 | | - } |
104 | | - } |
105 | | - |
106 | | - stage("Archive (${stageIdentifier})") { |
107 | | - if (!skipTests) { |
108 | | - String testReports |
109 | | - if (isMaven) { |
110 | | - testReports = '**/target/surefire-reports/**/*.xml,**/target/failsafe-reports/**/*.xml' |
111 | | - } else { |
112 | | - testReports = '**/build/test-results/**/*.xml' |
113 | | - } |
114 | | - junit testReports |
115 | | - // TODO do this in a finally-block so we capture all test results even if one branch aborts early |
116 | | - } |
117 | | - if (failFast && currentBuild.result == 'UNSTABLE') { |
118 | | - error 'There were test failures; halting early' |
119 | | - } |
120 | | - |
121 | | - if (first) { |
122 | | - referenceJobName = env.JOB_NAME.substring(0, env.JOB_NAME.lastIndexOf("/") + 1) + "master" |
123 | | - echo "Recording static analysis results on '${stageIdentifier}' using reference job '${referenceJobName}'" |
124 | | - |
125 | | - recordIssues enabledForFailure: true, |
126 | | - tool: mavenConsole(), |
127 | | - referenceJobName: referenceJobName |
128 | | - recordIssues enabledForFailure: true, |
129 | | - tools: [java(), javaDoc()], |
130 | | - sourceCodeEncoding: 'UTF-8', |
131 | | - filters:[excludeFile('.*Assert.java')], |
132 | | - referenceJobName: referenceJobName |
133 | | - recordIssues tools: [spotBugs(pattern: '**/target/spotbugsXml.xml'), |
134 | | - checkStyle(pattern: '**/target/checkstyle-result.xml'), |
135 | | - pmdParser(pattern: '**/target/pmd.xml'), |
136 | | - cpd(pattern: '**/target/cpd.xml')], |
137 | | - sourceCodeEncoding: 'UTF-8', |
138 | | - referenceJobName: referenceJobName |
139 | | - recordIssues enabledForFailure: true, tool: taskScanner( |
140 | | - includePattern:'**/*.java', |
141 | | - excludePattern:'**/target/**', |
142 | | - highTags:'FIXME', |
143 | | - normalTags:'TODO'), |
144 | | - sourceCodeEncoding: 'UTF-8', |
145 | | - referenceJobName: referenceJobName |
146 | | - } |
147 | | - else { |
148 | | - echo "Skipping static analysis results for ${stageIdentifier}" |
149 | | - } |
150 | | - if (doArchiveArtifacts) { |
151 | | - if (incrementals) { |
152 | | - String changelist = readFile(changelistF) |
153 | | - dir(m2repo) { |
154 | | - fingerprint '**/*-rc*.*/*-rc*.*' // includes any incrementals consumed |
155 | | - archiveArtifacts artifacts: "**/*$changelist/*$changelist*", |
156 | | - excludes: '**/*.lastUpdated', |
157 | | - allowEmptyArchive: true // in case we forgot to reincrementalify |
158 | | - } |
159 | | - publishingIncrementals = true |
160 | | - } else { |
161 | | - String artifacts |
162 | | - if (isMaven) { |
163 | | - artifacts = '**/target/*.hpi,**/target/*.jpi,**/target/*.jar' |
164 | | - } else { |
165 | | - artifacts = '**/build/libs/*.hpi,**/build/libs/*.jpi' |
166 | | - } |
167 | | - archiveArtifacts artifacts: artifacts, fingerprint: true |
168 | | - } |
169 | | - } else { |
170 | | - echo "INFO: Skipping archiving of artifacts" |
171 | | - } |
172 | | - } |
173 | | - } |
174 | | - } finally { |
175 | | - if (hasDockerLabel()) { |
176 | | - if(isUnix()) { |
177 | | - sh 'docker system prune --force --all || echo "Failed to cleanup docker images"' |
178 | | - } else { |
179 | | - bat 'docker system prune --force --all || echo "Failed to cleanup docker images"' |
180 | | - } |
181 | | - } |
182 | | - } |
183 | | - } |
184 | | - } |
185 | | - } |
186 | | - |
187 | | - parallel(tasks) |
188 | | - if (publishingIncrementals) { |
189 | | - infra.maybePublishIncrementals() |
190 | | - } else { |
191 | | - echo "INFO: Skipping publishing of incrementals" |
192 | | - } |
193 | | - |
194 | | -boolean hasDockerLabel() { |
195 | | - env.NODE_LABELS?.contains("docker") |
196 | | -} |
197 | | - |
198 | | -List<Map<String, String>> getConfigurations(Map params) { |
199 | | - boolean explicit = params.containsKey("configurations") |
200 | | - boolean implicit = params.containsKey('platforms') || params.containsKey('jdkVersions') || params.containsKey('jenkinsVersions') |
201 | | - |
202 | | - if (explicit && implicit) { |
203 | | - error '"configurations" option can not be used with either "platforms", "jdkVersions" or "jenkinsVersions"' |
204 | | - } |
205 | | - |
206 | | - |
207 | | - def configs = params.configurations |
208 | | - configs.each { c -> |
209 | | - if (!c.platform) { |
210 | | - error("Configuration field \"platform\" must be specified: $c") |
211 | | - } |
212 | | - if (!c.jdk) { |
213 | | - error("Configuration filed \"jdk\" must be specified: $c") |
214 | | - } |
215 | | - } |
216 | | - |
217 | | - if (explicit) return params.configurations |
218 | | - |
219 | | - def platforms = params.containsKey('platforms') ? params.platforms : ['linux', 'windows'] |
220 | | - def jdkVersions = params.containsKey('jdkVersions') ? params.jdkVersions : [8] |
221 | | - def jenkinsVersions = params.containsKey('jenkinsVersions') ? params.jenkinsVersions : [null] |
222 | | - |
223 | | - def ret = [] |
224 | | - for (p in platforms) { |
225 | | - for (jdk in jdkVersions) { |
226 | | - for (jenkins in jenkinsVersions) { |
227 | | - ret << [ |
228 | | - "platform": p, |
229 | | - "jdk": jdk, |
230 | | - "jenkins": jenkins, |
231 | | - "javaLevel": null // not supported in the old format |
232 | | - ] |
233 | | - } |
234 | | - } |
235 | | - } |
236 | | - return ret |
237 | | -} |
238 | | - |
239 | | -/** |
240 | | - * Get recommended configurations for testing. |
241 | | - * Includes testing Java 8 and 11 on the newest LTS. |
242 | | - */ |
243 | | -static List<Map<String, String>> recommendedConfigurations() { |
244 | | - def recentLTS = "2.164.1" |
245 | | - def configurations = [ |
246 | | - [ platform: "linux", jdk: "8", jenkins: null ], |
247 | | - [ platform: "windows", jdk: "8", jenkins: null ], |
248 | | - [ platform: "linux", jdk: "8", jenkins: recentLTS, javaLevel: "8" ], |
249 | | - [ platform: "windows", jdk: "8", jenkins: recentLTS, javaLevel: "8" ], |
250 | | - [ platform: "linux", jdk: "11", jenkins: recentLTS, javaLevel: "8" ], |
251 | | - [ platform: "windows", jdk: "11", jenkins: recentLTS, javaLevel: "8" ] |
252 | | - ] |
253 | | - return configurations |
254 | | -} |
| 5 | +buildPlugin(failFast: false, configurations: configurations) |
0 commit comments