Debug info
[lttng-ci.git] / dsl / kernel-lttng-modules.seed.groovy
CommitLineData
017c762b
JR
1enum KernelVersioning {
2 MAJOR,MINOR,REVISION,BUILD
3}
4
81470b33 5class 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
0bb106eb 90def kernelTagCutOff = new BasicVersion("4.3", "")
126608d3 91def modulesBranches = ["master","stable-2.5","stable-2.6", "stable-2.4"]
d11d0665
JR
92
93
017c762b
JR
94def linuxURL = "git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git"
95def modulesURL = "git://git.lttng.org/lttng-modules.git"
96
97// Linux specific variable
98String linuxCheckoutTo = "linux-source"
99String recipeCheckoutTo = "recipe"
100String modulesCheckoutTo = "lttng-modules"
101
102def linuxGitReference = "/home/jenkins/gitcache/linux-stable.git"
017c762b 103
d11d0665 104// Check if we are on jenkins
81f87da0
JR
105// Useful for outside jenkins devellopment related to groovy only scripting
106def isJenkinsInstance = binding.variables.containsKey('JENKINS_HOME')
107
132cba4a 108// Fetch tags and format
017c762b
JR
109// Split the string into sections based on |
110// And pipe the results together
132cba4a 111String process = "git ls-remote -t $linuxURL | cut -c42- | sort -V"
017c762b
JR
112def out = new StringBuilder()
113def err = new StringBuilder()
114Process result = process.tokenize( '|' ).inject( null ) { p, c ->
115 if( p )
116 p | c.execute()
117 else
118 c.execute()
119}
120
121result.waitForProcessOutput(out,err)
122
123if ( result.exitValue() == 0 ) {
124 def branches = out.readLines().collect {
d11d0665 125 // Scrap special string tag
5a67a345 126 it.replaceAll("\\^\\{\\}", '')
017c762b
JR
127 }
128
129 branches = branches.unique()
017c762b 130
81f87da0 131 List versions = []
017c762b 132 branches.each { branch ->
d11d0665
JR
133 def stripBranch = branch.replaceAll("rc", '').replaceAll(/refs\/tags\/v/,'')
134 BasicVersion kVersion = new BasicVersion(stripBranch, branch)
017c762b
JR
135 versions.add(kVersion)
136 }
137
81f87da0 138 // Sort the version via Comparable implementation of KernelVersion
017c762b
JR
139 versions = versions.sort()
140
132cba4a 141 // Find the version cutoff
d11d0665 142 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 143
831d4383
JR
144 // If error set cutoff on last so no job are created
145 if (cutoffPos == -1) {
146 cutoffPos = versions.size()
147 }
017c762b
JR
148 // Get last version and include only last rc
149 def last
150 def lastNoRcPos
151 last = versions.last()
152 if (last.rc != -1) {
153 int i = versions.size()-1
154 while (i > -1 && versions[i].rc != -1 ) {
155 i--
156 }
157 lastNoRcPos = i + 1
158 } else {
159 lastNoRcPos = versions.size()
160 }
161
d11d0665 162 String modulesPrefix = "lttng-modules"
162a2360 163 String kernelPrefix = "dsl-kernel"
d11d0665 164 String separator = "-"
831d4383 165
07f90dd7
JR
166
167 println("CutOff index")
168 println(cutoffPos)
169
170
d11d0665 171 // Actual job creation
017c762b 172 for (int i = cutoffPos; i < versions.size() ; i++) {
81f87da0 173
d11d0665 174 // Only create for valid build
017c762b
JR
175 if ( (i < lastNoRcPos && versions[i].rc == -1) || (i >= lastNoRcPos)) {
176 println ("Preparing job for")
d11d0665
JR
177
178 String jobName = kernelPrefix + separator + versions[i].print()
179
180 // Generate modules job based on supported modules jobs
181 def modulesJob = [:]
182 modulesBranches.each { branch ->
183 modulesJob[branch] = modulesPrefix + separator + branch + separator + jobName
184 }
185
186 // Jenkins only dsl
017c762b 187 println(jobName)
d11d0665
JR
188 if (isJenkinsInstance) {
189 matrixJob("${jobName}") {
190 using("linux-master")
191 scm {
192 git {
193 remote {
194 url("${linuxURL}")
195 }
196 branch(versions[i].gitRefs)
197 shallowClone(true)
198 relativeTargetDir(linuxCheckoutTo)
199 reference(linuxGitReference)
200 }
201 }
202 publishers {
203 modulesJob.each {
204 downstream(it.value, 'SUCCESS')
205 }
206 }
207 }
208 }
209 // Corresponding Module job
ef0e4e86
JR
210 modulesJob.each { job ->
211 println("\t" + job.key + " " + job.value)
d11d0665 212 if (isJenkinsInstance) {
ef0e4e86 213 matrixJob(job.value) {
d11d0665
JR
214 using("modules")
215 multiscm {
216 git {
217 remote {
218 name(kernelPrefix)
219 url("${linuxURL}")
220 }
221 branch(versions[i].gitRefs)
222 shallowClone(true)
223 relativeTargetDir(linuxCheckoutTo)
224 reference(linuxGitReference)
225 }
226 git {
227 remote {
228 name(modulesPrefix)
229 url(modulesURL)
230 }
ef0e4e86 231 branch(job.key)
d11d0665
JR
232 relativeTargetDir(modulesCheckoutTo)
233 }
234 }
235 steps {
236 copyArtifacts("${jobName}/arch=\$arch", "linux-artifact/**", '', false, false) {
237 latestSuccessful(true) // Latest successful build
238 }
239 shell(readFileFromWorkspace('lttng-modules/lttng-modules-dsl-master.sh'))
240 }
241 }
242 }
243 }
244 }
245 }
162a2360
JR
246
247 // Trigger generations
248 def dslTriggerKernel = """\
249
250import hudson.model.*
251import hudson.AbortException
252import hudson.console.HyperlinkNote
253import java.util.concurrent.CancellationException
254
255
256def jobs = hudson.model.Hudson.instance.items
257def fail = false
b46e797c 258def jobStartWith = "${kernelPrefix}"
162a2360
JR
259
260def anotherBuild
261jobs.each { job ->
262 def jobName = job.getName()
263 if (jobName.startsWith(jobStartWith)) {
264 def lastBuild = job.getLastBuild()
265 if (lastBuild == null) {
266 try {
267 def future = job.scheduleBuild2(0, new Cause.UpstreamCause(build))
268 println "\\tWaiting for the completion of " + HyperlinkNote.encodeTo('/' + job.url, job.fullDisplayName)
269 anotherBuild = future.get()
270 } catch (CancellationException x) {
271 throw new AbortException("\${job.fullDisplayName} aborted.")
272 }
273 println HyperlinkNote.encodeTo('/' + anotherBuild.url, anotherBuild.fullDisplayName) + " completed. Result was " + anotherBuild.result
274
275 build.result = anotherBuild.result
276 if (anotherBuild.result != Result.SUCCESS && anotherBuild.result != Result.UNSTABLE) {
277 // We abort this build right here and now.
278 fail = true
279 println("Build Failed")
280 }
281 } else {
282 println("\\tAlready built")
283 }
284 }
285}
286
c76d8fe2
JR
287if (fail){
288 throw new AbortException("Some job failed")
289}
290"""
291 def dslTriggerModule = """\
292import hudson.model.*
293import hudson.AbortException
294import hudson.console.HyperlinkNote
295import java.util.concurrent.CancellationException
296
297
298def jobs = hudson.model.Hudson.instance.items
299def fail = false
6a7fce90 300def jobStartWith = "JOBPREFIX"
c76d8fe2
JR
301
302def anotherBuild
303jobs.each { job ->
304 def jobName = job.getName()
305 if (jobName.startsWith(jobStartWith)) {
306 def lastBuild = job.getLastBuild()
307 if (lastBuild == null) {
308 try {
309 def future = job.scheduleBuild2(0, new Cause.UpstreamCause(build))
310 println "\\tWaiting for the completion of " + HyperlinkNote.encodeTo('/' + job.url, job.fullDisplayName)
311 anotherBuild = future.get()
312 } catch (CancellationException x) {
313 throw new AbortException("\${job.fullDisplayName} aborted.")
314 }
315 println HyperlinkNote.encodeTo('/' + anotherBuild.url, anotherBuild.fullDisplayName) + " completed. Result was " + anotherBuild.result
316
317 build.result = anotherBuild.result
318 if (anotherBuild.result != Result.SUCCESS && anotherBuild.result != Result.UNSTABLE) {
319 // We abort this build right here and now.
320 fail = true
321 println("Build Failed")
322 }
323 } else {
324 println("\\tAlready built")
325 }
326 }
327}
328
162a2360
JR
329if (fail){
330 throw new AbortException("Some job failed")
331}
332"""
333 if (isJenkinsInstance) {
334 freeStyleJob("dsl-trigger-kernel") {
335 steps {
6f47f2cd 336 systemGroovyCommand(dslTriggerKernel)
162a2360 337 }
d585fdc4
JR
338 triggers {
339 cron("H 0 * * *")
340 }
c76d8fe2
JR
341 }
342
343 modulesBranches.each { branch ->
344 freeStyleJob("dsl-trigger-module-${branch}") {
345 steps {
6a7fce90 346 systemGroovyCommand(dslTriggerModule.replaceAll("JOBPREFIX",modulesPrefix + separator + branch + separator))
c76d8fe2 347 }
d585fdc4
JR
348 triggers {
349 scm('@daily')
350 }
c76d8fe2
JR
351 }
352 }
162a2360 353 }
017c762b 354}
This page took 0.037677 seconds and 4 git commands to generate.