Add asciidoc dep to lttng-tools
[lttng-ci.git] / scripts / lttng-modules / master-vanilla.groovy
CommitLineData
f3d8604b
MJ
1/**
2 * Copyright (C) 2016 - Michael Jeanson <mjeanson@efficios.com>
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18import hudson.model.*
19import hudson.AbortException
20import hudson.console.HyperlinkNote
21import java.util.concurrent.CancellationException
22import org.eclipse.jgit.api.Git
23import org.eclipse.jgit.lib.Ref
24
25
26class kVersion implements Comparable<kVersion> {
27
28 Integer major = 0;
29 Integer majorB = 0;
30 Integer minor = 0;
31 Integer patch = 0;
32 Integer rc = Integer.MAX_VALUE;
33
34 kVersion() {}
35
36 kVersion(version) {
37 this.parse(version)
38 }
39
40 def parse(version) {
41 this.major = 0
42 this.majorB = 0
43 this.minor = 0
44 this.patch = 0
45 this.rc = Integer.MAX_VALUE
46
47 def match = version =~ /^v(\d+)\.(\d+)(\.(\d+))?(\.(\d+))?(-rc(\d+))?$/
48 if (!match) {
49 throw new Exception("Invalid kernel version: ${version}")
50 }
51
52 Integer offset = 0;
53
54 // Major
55 this.major = Integer.parseInt(match.group(1))
56 if (this.major <= 2) {
57 offset = 2
58 this.majorB = Integer.parseInt(match.group(2))
59 }
60
61 // Minor
62 if (match.group(2 + offset) != null) {
63 this.minor = Integer.parseInt(match.group(2 + offset))
64 }
65
66 // Patch level
67 if (match.group(4 + offset) != null) {
68 this.patch = Integer.parseInt(match.group(4 + offset))
69 }
70
71 // RC
72 if (match.group(8) != null) {
73 this.rc = Integer.parseInt(match.group(8))
74 }
75 }
76
77 // Return true if this version is a release candidate
78 Boolean isRC() {
79 return this.rc != Integer.MAX_VALUE
80 }
81
82 @Override int compareTo(kVersion o) {
83 if (this.major != o.major) {
84 return Integer.compare(this.major, o.major);
85 }
86 if (this.majorB != o.majorB) {
87 return Integer.compare(this.majorB, o.majorB);
88 }
89 if (this.minor != o.minor) {
90 return Integer.compare(this.minor, o.minor);
91 }
92 if (this.patch != o.patch) {
93 return Integer.compare(this.patch, o.patch);
94 }
95 if (this.rc != o.rc) {
96 return Integer.compare(this.rc, o.rc);
97 }
98
99 // Same version
100 return 0;
101 }
102
103 String toString() {
104 String vString = "v${this.major}"
105
106 if (this.majorB > 0) {
107 vString = vString.concat(".${this.majorB}")
108 }
109
110 vString = vString.concat(".${this.minor}")
111
112 if (this.patch > 0) {
113 vString = vString.concat(".${this.patch}")
114 }
115
116 if (this.rc > 0 && this.rc < Integer.MAX_VALUE) {
117 vString = vString.concat("-rc${this.rc}")
118 }
119 return vString
120 }
121}
122
123
124// Retrieve parameters of the current build
125def mversion = build.buildVariableResolver.resolve('mversion')
126def maxConcurrentBuild = build.buildVariableResolver.resolve('maxConcurrentBuild')
127def kgitrepo = build.buildVariableResolver.resolve('kgitrepo')
128def kverfloor = new kVersion(build.buildVariableResolver.resolve('kverfloor'))
129def job = Hudson.instance.getJob(build.buildVariableResolver.resolve('kbuildjob'))
130
131// Get the out variable
132def config = new HashMap()
133def bindings = getBinding()
134config.putAll(bindings.getVariables())
135def out = config['out']
136
137def jlc = new jenkins.model.JenkinsLocationConfiguration()
138def jenkinsUrl = jlc.url
139
140// Get tags from git repository
141def refs = Git.lsRemoteRepository().setTags(true).setRemote(kgitrepo).call();
142
143// Get kernel versions to build
144def kversions = []
145def kversionsRC = []
146for (ref in refs) {
147 def match = ref.getName() =~ /^refs\/tags\/(v[\d\.]+(-rc(\d+))?)$/
148
149 if (match) {
150 def v = new kVersion(match.group(1))
151
152 if (v >= kverfloor) {
153 if (v.isRC()) {
154 kversionsRC.add(v)
155 } else {
156 kversions.add(v)
157 }
158 }
159 }
160}
161
162kversions.sort()
163kversionsRC.sort()
164
165// If the last RC version is newer than the last stable, add it to the build list
166if (kversionsRC.last() > kversions.last()) {
167 kversions.add(kversionsRC.last())
168}
169
170// Debug
171println "Building the following kernel versions:"
172for (k in kversions) {
173 println k
174}
175
176// Debug: Stop build here
177//throw new InterruptedException()
178
179def joburl = HyperlinkNote.encodeTo('/' + job.url, job.fullDisplayName)
180
181def allBuilds = []
182def ongoingBuild = []
183def failedRuns = []
184def isFailed = false
185
186// Loop while we have kernel versions remaining or jobs running
187while ( kversions.size() != 0 || ongoingBuild.size() != 0 ) {
188
189 if(ongoingBuild.size() < maxConcurrentBuild.toInteger() && kversions.size() != 0) {
190 def kversion = kversions.pop()
191 def job_params = [
192 new StringParameterValue('mversion', mversion),
193 new StringParameterValue('kversion', kversion.toString()),
194 new StringParameterValue('kgitrepo', kgitrepo),
195 ]
196
197 // Launch the parametrized build
198 def param_build = job.scheduleBuild2(0, new Cause.UpstreamCause(build), new ParametersAction(job_params))
199 println "triggering ${joburl} for the ${mversion} branch on kernel ${kversion}"
200
201 // Add it to the ongoing build queue
202 ongoingBuild.push(param_build)
203
204 } else {
205
206 println "Waiting... Queued: " + kversions.size() + " Running: " + ongoingBuild.size()
207 try {
208 Thread.sleep(5000)
209 } catch(e) {
210 if (e in InterruptedException) {
211 build.setResult(hudson.model.Result.ABORTED)
212 throw new InterruptedException()
213 } else {
214 throw(e)
215 }
216 }
217
218 def i = ongoingBuild.iterator()
219 while ( i.hasNext() ) {
220 currentBuild = i.next()
221 if ( currentBuild.isCancelled() || currentBuild.isDone() ) {
222 // Remove from queue
223 i.remove()
224
225 // Print results
226 def matrixParent = currentBuild.get()
227 allBuilds.add(matrixParent)
228 def kernelStr = matrixParent.buildVariableResolver.resolve("kversion")
229 println "${matrixParent.fullDisplayName} (${kernelStr}) completed with status ${matrixParent.result}"
230
231 // Process child runs of matrixBuild
232 def childRuns = matrixParent.getRuns()
233 for ( childRun in childRuns ) {
234 println "\t${childRun.fullDisplayName} (${kernelStr}) completed with status ${childRun.result}"
235 if (childRun.result != Result.SUCCESS) {
236 failedRuns.add(childRun)
237 isFailed = true
238 }
239 }
240 }
241 }
242 }
243}
244
245// Get log of failed runs
246for (failedRun in failedRuns) {
247 println "---START---"
248 failedRun.writeWholeLogTo(out)
249 println "---END---"
250}
251
252println "---Build report---"
253for (b in allBuilds) {
254 def kernelStr = b.buildVariableResolver.resolve("kversion")
255 println "${b.fullDisplayName} (${kernelStr}) completed with status ${b.result}"
256}
257
258// Clean all builds
259// TODO: Delete only builds generated from this job run
260for (b in job.getBuilds()) {
261 b.delete()
262}
263
264// Mark this build failed if any child build has failed
265if (isFailed) {
266 build.getExecutor().interrupt(Result.FAILURE)
267}
268
269// EOF
This page took 0.031327 seconds and 4 git commands to generate.