Commit | Line | Data |
---|---|---|
017c762b JR |
1 | enum KernelVersioning { |
2 | MAJOR,MINOR,REVISION,BUILD | |
3 | } | |
4 | ||
81470b33 | 5 | class BasicVersion implements Comparable<BasicVersion> { |
017c762b JR |
6 | int major = -1 |
7 | int minor = -1 | |
8 | int revision = -1 | |
9 | int build = -1 | |
10 | int rc = -1 | |
5a67a345 | 11 | String gitRefs |
017c762b JR |
12 | |
13 | // Default Constructor | |
81470b33 | 14 | BasicVersion() {} |
017c762b | 15 | |
81470b33 JR |
16 | // Parse a version string of format X.Y.Z.W-A |
17 | BasicVersion(String version, String ref) { | |
5a67a345 | 18 | gitRefs = ref |
d11d0665 | 19 | def tokenVersion |
017c762b JR |
20 | def token |
21 | if (version.contains('-')) { | |
22 | // Release canditate | |
23 | token = version.tokenize('-') | |
24 | tokenVersion = token[0] | |
81470b33 | 25 | if (token[1]?.isInteger()) { |
017c762b JR |
26 | rc = token[1].toInteger() |
27 | } | |
28 | } else { | |
29 | tokenVersion = version | |
30 | } | |
31 | ||
32 | tokenVersion = tokenVersion.tokenize('.') | |
33 | ||
34 | def tagEnum = KernelVersioning.MAJOR | |
35 | tokenVersion.each { | |
81470b33 | 36 | if (it?.isInteger()) { |
017c762b JR |
37 | switch (tagEnum) { |
38 | case KernelVersioning.MAJOR: | |
39 | major = it.toInteger() | |
40 | tagEnum = KernelVersioning.MINOR | |
41 | break | |
42 | case KernelVersioning.MINOR: | |
43 | minor = it.toInteger() | |
44 | tagEnum = KernelVersioning.REVISION | |
45 | break | |
46 | case KernelVersioning.REVISION: | |
47 | revision = it.toInteger() | |
48 | tagEnum = KernelVersioning.BUILD | |
49 | break | |
50 | case KernelVersioning.BUILD: | |
51 | build = it.toInteger() | |
52 | tagEnum = -1 | |
53 | break | |
54 | default: | |
55 | println("Unsupported version extension") | |
56 | println("Trying to parse: ${version}") | |
57 | println("Invalid sub version value: ${it}") | |
d11d0665 | 58 | //TODO: throw exception for jenkins |
017c762b JR |
59 | } |
60 | } | |
61 | } | |
62 | } | |
63 | ||
017c762b JR |
64 | String print() { |
65 | String ret = "" | |
66 | if (major != -1) { | |
67 | ret += major | |
68 | if (minor != -1) { | |
69 | ret += "." + minor | |
70 | if (revision != -1) { | |
71 | ret += "." + revision | |
72 | if (build != -1) { | |
73 | ret += "." + build | |
74 | } | |
75 | } | |
76 | } | |
77 | if (rc != -1) { | |
5a67a345 | 78 | ret += "-rc" + rc |
017c762b JR |
79 | } |
80 | } | |
81 | return ret | |
82 | } | |
83 | ||
84 | @Override | |
81470b33 | 85 | int compareTo(BasicVersion kernelVersion) { |
017c762b JR |
86 | return major <=> kernelVersion.major ?: minor <=> kernelVersion.minor ?: revision <=> kernelVersion.revision ?: build <=> kernelVersion.build ?: rc <=> kernelVersion.rc |
87 | } | |
88 | } | |
89 | ||
6f47f2cd | 90 | def kernelTagCutOff = new BasicVersion("4.0", "") |
d11d0665 JR |
91 | def modulesBranches = ["master","stable-2.5.0","stable-2.6.0", "stable-2.4.0"] |
92 | ||
93 | ||
017c762b JR |
94 | def linuxURL = "git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git" |
95 | def modulesURL = "git://git.lttng.org/lttng-modules.git" | |
96 | ||
97 | // Linux specific variable | |
98 | String linuxCheckoutTo = "linux-source" | |
99 | String recipeCheckoutTo = "recipe" | |
100 | String modulesCheckoutTo = "lttng-modules" | |
101 | ||
102 | def linuxGitReference = "/home/jenkins/gitcache/linux-stable.git" | |
103 | String process = "git ls-remote -t $linuxURL | cut -c42- | sort -V" | |
104 | ||
d11d0665 | 105 | // Check if we are on jenkins |
81f87da0 JR |
106 | // Useful for outside jenkins devellopment related to groovy only scripting |
107 | def isJenkinsInstance = binding.variables.containsKey('JENKINS_HOME') | |
108 | ||
017c762b JR |
109 | // Split the string into sections based on | |
110 | // And pipe the results together | |
111 | def out = new StringBuilder() | |
112 | def err = new StringBuilder() | |
113 | Process result = process.tokenize( '|' ).inject( null ) { p, c -> | |
114 | if( p ) | |
115 | p | c.execute() | |
116 | else | |
117 | c.execute() | |
118 | } | |
119 | ||
120 | result.waitForProcessOutput(out,err) | |
121 | ||
122 | if ( result.exitValue() == 0 ) { | |
123 | def branches = out.readLines().collect { | |
d11d0665 | 124 | // Scrap special string tag |
5a67a345 | 125 | it.replaceAll("\\^\\{\\}", '') |
017c762b JR |
126 | } |
127 | ||
128 | branches = branches.unique() | |
017c762b | 129 | |
81f87da0 | 130 | List versions = [] |
017c762b | 131 | branches.each { branch -> |
d11d0665 JR |
132 | def stripBranch = branch.replaceAll("rc", '').replaceAll(/refs\/tags\/v/,'') |
133 | BasicVersion kVersion = new BasicVersion(stripBranch, branch) | |
017c762b JR |
134 | versions.add(kVersion) |
135 | } | |
136 | ||
81f87da0 | 137 | // Sort the version via Comparable implementation of KernelVersion |
017c762b JR |
138 | versions = versions.sort() |
139 | ||
81f87da0 | 140 | // Find the version cut of |
d11d0665 | 141 | def cutoffPos = versions.findIndexOf{(it.major >= kernelTagCutOff.major) && (it.minor >= kernelTagCutOff.minor) && (it.revision >= kernelTagCutOff.revision) && (it.build >= kernelTagCutOff.build) && (it.rc >= kernelTagCutOff.rc)} |
017c762b | 142 | |
017c762b JR |
143 | // Get last version and include only last rc |
144 | def last | |
145 | def lastNoRcPos | |
146 | last = versions.last() | |
147 | if (last.rc != -1) { | |
148 | int i = versions.size()-1 | |
149 | while (i > -1 && versions[i].rc != -1 ) { | |
150 | i-- | |
151 | } | |
152 | lastNoRcPos = i + 1 | |
153 | } else { | |
154 | lastNoRcPos = versions.size() | |
155 | } | |
156 | ||
d11d0665 | 157 | String modulesPrefix = "lttng-modules" |
162a2360 | 158 | String kernelPrefix = "dsl-kernel" |
d11d0665 JR |
159 | String separator = "-" |
160 | // Actual job creation | |
017c762b | 161 | for (int i = cutoffPos; i < versions.size() ; i++) { |
81f87da0 | 162 | |
d11d0665 | 163 | // Only create for valid build |
017c762b JR |
164 | if ( (i < lastNoRcPos && versions[i].rc == -1) || (i >= lastNoRcPos)) { |
165 | println ("Preparing job for") | |
d11d0665 JR |
166 | |
167 | String jobName = kernelPrefix + separator + versions[i].print() | |
168 | ||
169 | // Generate modules job based on supported modules jobs | |
170 | def modulesJob = [:] | |
171 | modulesBranches.each { branch -> | |
172 | modulesJob[branch] = modulesPrefix + separator + branch + separator + jobName | |
173 | } | |
174 | ||
175 | // Jenkins only dsl | |
017c762b | 176 | println(jobName) |
d11d0665 JR |
177 | if (isJenkinsInstance) { |
178 | matrixJob("${jobName}") { | |
179 | using("linux-master") | |
180 | scm { | |
181 | git { | |
182 | remote { | |
183 | url("${linuxURL}") | |
184 | } | |
185 | branch(versions[i].gitRefs) | |
186 | shallowClone(true) | |
187 | relativeTargetDir(linuxCheckoutTo) | |
188 | reference(linuxGitReference) | |
189 | } | |
190 | } | |
191 | publishers { | |
192 | modulesJob.each { | |
193 | downstream(it.value, 'SUCCESS') | |
194 | } | |
195 | } | |
196 | } | |
197 | } | |
198 | // Corresponding Module job | |
ef0e4e86 JR |
199 | modulesJob.each { job -> |
200 | println("\t" + job.key + " " + job.value) | |
d11d0665 | 201 | if (isJenkinsInstance) { |
ef0e4e86 | 202 | matrixJob(job.value) { |
d11d0665 JR |
203 | using("modules") |
204 | multiscm { | |
205 | git { | |
206 | remote { | |
207 | name(kernelPrefix) | |
208 | url("${linuxURL}") | |
209 | } | |
210 | branch(versions[i].gitRefs) | |
211 | shallowClone(true) | |
212 | relativeTargetDir(linuxCheckoutTo) | |
213 | reference(linuxGitReference) | |
214 | } | |
215 | git { | |
216 | remote { | |
217 | name(modulesPrefix) | |
218 | url(modulesURL) | |
219 | } | |
ef0e4e86 | 220 | branch(job.key) |
d11d0665 JR |
221 | relativeTargetDir(modulesCheckoutTo) |
222 | } | |
223 | } | |
224 | steps { | |
225 | copyArtifacts("${jobName}/arch=\$arch", "linux-artifact/**", '', false, false) { | |
226 | latestSuccessful(true) // Latest successful build | |
227 | } | |
228 | shell(readFileFromWorkspace('lttng-modules/lttng-modules-dsl-master.sh')) | |
229 | } | |
230 | } | |
231 | } | |
232 | } | |
233 | } | |
234 | } | |
162a2360 JR |
235 | |
236 | // Trigger generations | |
237 | def dslTriggerKernel = """\ | |
238 | ||
239 | import hudson.model.* | |
240 | import hudson.AbortException | |
241 | import hudson.console.HyperlinkNote | |
242 | import java.util.concurrent.CancellationException | |
243 | ||
244 | ||
245 | def jobs = hudson.model.Hudson.instance.items | |
246 | def fail = false | |
b46e797c | 247 | def jobStartWith = "${kernelPrefix}" |
162a2360 JR |
248 | |
249 | def anotherBuild | |
250 | jobs.each { job -> | |
251 | def jobName = job.getName() | |
252 | if (jobName.startsWith(jobStartWith)) { | |
253 | def lastBuild = job.getLastBuild() | |
254 | if (lastBuild == null) { | |
255 | try { | |
256 | def future = job.scheduleBuild2(0, new Cause.UpstreamCause(build)) | |
257 | println "\\tWaiting for the completion of " + HyperlinkNote.encodeTo('/' + job.url, job.fullDisplayName) | |
258 | anotherBuild = future.get() | |
259 | } catch (CancellationException x) { | |
260 | throw new AbortException("\${job.fullDisplayName} aborted.") | |
261 | } | |
262 | println HyperlinkNote.encodeTo('/' + anotherBuild.url, anotherBuild.fullDisplayName) + " completed. Result was " + anotherBuild.result | |
263 | ||
264 | build.result = anotherBuild.result | |
265 | if (anotherBuild.result != Result.SUCCESS && anotherBuild.result != Result.UNSTABLE) { | |
266 | // We abort this build right here and now. | |
267 | fail = true | |
268 | println("Build Failed") | |
269 | } | |
270 | } else { | |
271 | println("\\tAlready built") | |
272 | } | |
273 | } | |
274 | } | |
275 | ||
c76d8fe2 JR |
276 | if (fail){ |
277 | throw new AbortException("Some job failed") | |
278 | } | |
279 | """ | |
280 | def dslTriggerModule = """\ | |
281 | import hudson.model.* | |
282 | import hudson.AbortException | |
283 | import hudson.console.HyperlinkNote | |
284 | import java.util.concurrent.CancellationException | |
285 | ||
286 | ||
287 | def jobs = hudson.model.Hudson.instance.items | |
288 | def fail = false | |
289 | def jobStartWith = "${modulesPrefix + separator}%1$s" | |
290 | ||
291 | def anotherBuild | |
292 | jobs.each { job -> | |
293 | def jobName = job.getName() | |
294 | if (jobName.startsWith(jobStartWith)) { | |
295 | def lastBuild = job.getLastBuild() | |
296 | if (lastBuild == null) { | |
297 | try { | |
298 | def future = job.scheduleBuild2(0, new Cause.UpstreamCause(build)) | |
299 | println "\\tWaiting for the completion of " + HyperlinkNote.encodeTo('/' + job.url, job.fullDisplayName) | |
300 | anotherBuild = future.get() | |
301 | } catch (CancellationException x) { | |
302 | throw new AbortException("\${job.fullDisplayName} aborted.") | |
303 | } | |
304 | println HyperlinkNote.encodeTo('/' + anotherBuild.url, anotherBuild.fullDisplayName) + " completed. Result was " + anotherBuild.result | |
305 | ||
306 | build.result = anotherBuild.result | |
307 | if (anotherBuild.result != Result.SUCCESS && anotherBuild.result != Result.UNSTABLE) { | |
308 | // We abort this build right here and now. | |
309 | fail = true | |
310 | println("Build Failed") | |
311 | } | |
312 | } else { | |
313 | println("\\tAlready built") | |
314 | } | |
315 | } | |
316 | } | |
317 | ||
162a2360 JR |
318 | if (fail){ |
319 | throw new AbortException("Some job failed") | |
320 | } | |
321 | """ | |
322 | if (isJenkinsInstance) { | |
323 | freeStyleJob("dsl-trigger-kernel") { | |
324 | steps { | |
6f47f2cd | 325 | systemGroovyCommand(dslTriggerKernel) |
162a2360 | 326 | } |
c76d8fe2 JR |
327 | } |
328 | ||
329 | modulesBranches.each { branch -> | |
330 | freeStyleJob("dsl-trigger-module-${branch}") { | |
331 | steps { | |
332 | systemGroovyCommand(snprintf(dslTriggerModule,[branch])) | |
333 | } | |
334 | } | |
335 | } | |
162a2360 | 336 | } |
017c762b | 337 | } |