1 enum KernelVersioning {
2 MAJOR,MINOR,REVISION,BUILD
5 class BasicVersion implements Comparable<BasicVersion> {
13 // Default Constructor
16 // Parse a version string of format X.Y.Z.W-A
17 BasicVersion(String version, String ref) {
21 if (version.contains('-')) {
23 token = version.tokenize('-')
24 tokenVersion = token[0]
25 if (token[1]?.isInteger()) {
26 rc = token[1].toInteger()
29 tokenVersion = version
32 tokenVersion = tokenVersion.tokenize('.')
34 def tagEnum = KernelVersioning.MAJOR
36 if (it?.isInteger()) {
38 case KernelVersioning.MAJOR:
39 major = it.toInteger()
40 tagEnum = KernelVersioning.MINOR
42 case KernelVersioning.MINOR:
43 minor = it.toInteger()
44 tagEnum = KernelVersioning.REVISION
46 case KernelVersioning.REVISION:
47 revision = it.toInteger()
48 tagEnum = KernelVersioning.BUILD
50 case KernelVersioning.BUILD:
51 build = it.toInteger()
55 println("Unsupported version extension")
56 println("Trying to parse: ${version}")
57 println("Invalid sub version value: ${it}")
58 //TODO: throw exception for jenkins
85 int compareTo(BasicVersion kernelVersion) {
86 return major <=> kernelVersion.major ?: minor <=> kernelVersion.minor ?: revision <=> kernelVersion.revision ?: build <=> kernelVersion.build ?: rc <=> kernelVersion.rc
90 def kernelTagCutOff = new BasicVersion("2.6.36", "")
91 def modulesBranches = ["master", "stable-2.5", "stable-2.6"]
93 //def modulesBranches = ["master","stable-2.5","stable-2.6", "stable-2.4"]
95 def linuxURL = "git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git"
96 def modulesURL = "git://git.lttng.org/lttng-modules.git"
98 // Linux specific variable
99 String linuxCheckoutTo = "linux-source"
100 String recipeCheckoutTo = "recipe"
101 String modulesCheckoutTo = "lttng-modules"
103 def linuxGitReference = "/home/jenkins/gitcache/linux-stable.git"
105 // Check if we are on jenkins
106 // Useful for outside jenkins devellopment related to groovy only scripting
107 def isJenkinsInstance = binding.variables.containsKey('JENKINS_HOME')
109 // Fetch tags and format
110 // Split the string into sections based on |
111 // And pipe the results together
112 String process = "git ls-remote -t $linuxURL | cut -c42- | sort -V"
113 def out = new StringBuilder()
114 def err = new StringBuilder()
115 Process result = process.tokenize( '|' ).inject( null ) { p, c ->
122 result.waitForProcessOutput(out,err)
124 if ( result.exitValue() == 0 ) {
125 def branches = out.readLines().collect {
126 // Scrap special string tag
127 it.replaceAll("\\^\\{\\}", '')
130 branches = branches.unique()
133 branches.each { branch ->
134 def stripBranch = branch.replaceAll("rc", '').replaceAll(/refs\/tags\/v/,'')
135 BasicVersion kVersion = new BasicVersion(stripBranch, branch)
136 versions.add(kVersion)
139 // Sort the version via Comparable implementation of KernelVersion
140 versions = versions.sort()
142 // Find the version cutoff
143 def cutoffPos = versions.findIndexOf{(it.major >= kernelTagCutOff.major) && (it.minor >= kernelTagCutOff.minor) && (it.revision >= kernelTagCutOff.revision) && (it.build >= kernelTagCutOff.build) && (it.rc >= kernelTagCutOff.rc)}
145 // If error set cutoff on last so no job are created
146 if (cutoffPos == -1) {
147 cutoffPos = versions.size()
149 // Get last version and include only last rc
152 last = versions.last()
154 int i = versions.size()-1
155 while (i > -1 && versions[i].rc != -1 ) {
160 lastNoRcPos = versions.size()
163 String modulesPrefix = "lttng-modules"
164 String kernelPrefix = "dsl-kernel"
165 String separator = "-"
168 println("CutOff index")
172 // Actual job creation
173 for (int i = cutoffPos; i < versions.size() ; i++) {
175 // Only create for valid build
176 if ( (i < lastNoRcPos && versions[i].rc == -1) || (i >= lastNoRcPos)) {
177 println ("Preparing job for")
179 String jobName = kernelPrefix + separator + versions[i].print()
181 // Generate modules job based on supported modules jobs
183 modulesBranches.each { branch ->
184 modulesJob[branch] = modulesPrefix + separator + branch + separator + jobName
189 if (isJenkinsInstance) {
190 matrixJob("${jobName}") {
191 using("linux-master")
197 branch(versions[i].gitRefs)
199 relativeTargetDir(linuxCheckoutTo)
200 reference(linuxGitReference)
205 downstream(it.value, 'SUCCESS')
210 // Corresponding Module job
211 modulesJob.each { job ->
212 println("\t" + job.key + " " + job.value)
213 if (isJenkinsInstance) {
214 matrixJob(job.value) {
222 branch(versions[i].gitRefs)
224 relativeTargetDir(linuxCheckoutTo)
225 reference(linuxGitReference)
233 relativeTargetDir(modulesCheckoutTo)
237 copyArtifacts("${jobName}/arch=\$arch", "linux-artifact/**", '', false, false) {
238 latestSuccessful(true) // Latest successful build
240 shell(readFileFromWorkspace('lttng-modules/lttng-modules-dsl-master.sh'))
248 // Trigger generations
249 def dslTriggerKernel = """\
250 import hudson.model.*
251 import hudson.AbortException
252 import hudson.console.HyperlinkNote
253 import java.util.concurrent.CancellationException
254 import java.util.Random
257 Random random = new Random()
258 def jobs = hudson.model.Hudson.instance.items
260 def jobStartWith = "dsl-kernel-"
266 def jobName = job.getName()
267 if (jobName.startsWith(jobStartWith)) {
268 counter = counter + 1
269 def lastBuild = job.getLastBuild()
270 if (lastBuild == null || lastBuild.result != Result.SUCCESS) {
273 println("\\tAlready built")
278 println "Kernel total "+ counter
279 println "Kernel to build "+ toBuild.size()
282 def kernelEnabledNode = 0
283 hudson.model.Hudson.instance.nodes.each { node ->
284 if (node.getLabelString().contains("kernel")){
288 println "Nb of live kernel enabled build node "+ kernelEnabledNode
290 def ongoingBuild = []
292 while (toBuild.size() != 0) {
293 if(ongoingBuild.size() <= (kernelEnabledNode.intdiv(2))) {
294 def job = toBuild.pop()
295 ongoingBuild.push(job.scheduleBuild2(0))
296 println "\\t trigering" + HyperlinkNote.encodeTo('/' + job.url, job.fullDisplayName)
298 wait(random.nextInt(120000)
299 ongoingBuild.removeAll{ it.isCancelled() || it.isDone() }
304 throw new AbortException("Some job failed")
307 def dslTriggerModule = """\
308 import hudson.model.*
309 import hudson.AbortException
310 import hudson.console.HyperlinkNote
311 import java.util.concurrent.CancellationException
312 import java.util.Random
315 Random random = new Random()
316 def jobs = hudson.model.Hudson.instance.items
318 def jobStartWith = "JOBPREFIX"
324 def jobName = job.getName()
325 if (jobName.startsWith(jobStartWith)) {
326 counter = counter + 1
332 def kernelEnabledNode = 0
333 hudson.model.Hudson.instance.nodes.each { node ->
334 if (node.getLabelString().contains("kernel")){
339 def ongoingBuild = []
340 while (toBuild.size() != 0) {
341 if(ongoingBuild.size() <= (kernelEnabledNode.intdiv(2))) {
342 def job = toBuild.pop()
343 ongoingBuild.push(job.scheduleBuild2(0))
344 println "\\t trigering " + HyperlinkNote.encodeTo('/' + job.url, job.fullDisplayName)
346 wait(random.nextInt(60000)
347 ongoingBuild.removeAll{ it.isCancelled() || it.isDone() }
352 throw new AbortException("Some job failed")
355 if (isJenkinsInstance) {
356 freeStyleJob("dsl-trigger-kernel") {
358 systemGroovyCommand(dslTriggerKernel)
365 modulesBranches.each { branch ->
366 freeStyleJob("dsl-trigger-module-${branch}") {
368 systemGroovyCommand(dslTriggerModule.replaceAll("JOBPREFIX",modulesPrefix + separator + branch + separator))