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("4.3", "")
91 def modulesBranches = ["master","stable-2.5","stable-2.6", "stable-2.4"]
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"
97 // Linux specific variable
98 String linuxCheckoutTo = "linux-source"
99 String recipeCheckoutTo = "recipe"
100 String modulesCheckoutTo = "lttng-modules"
102 def linuxGitReference = "/home/jenkins/gitcache/linux-stable.git"
104 // Check if we are on jenkins
105 // Useful for outside jenkins devellopment related to groovy only scripting
106 def isJenkinsInstance = binding.variables.containsKey('JENKINS_HOME')
108 // Fetch tags and format
109 // Split the string into sections based on |
110 // And pipe the results together
111 String process = "git ls-remote -t $linuxURL | cut -c42- | sort -V"
112 def out = new StringBuilder()
113 def err = new StringBuilder()
114 Process result = process.tokenize( '|' ).inject( null ) { p, c ->
121 result.waitForProcessOutput(out,err)
123 if ( result.exitValue() == 0 ) {
124 def branches = out.readLines().collect {
125 // Scrap special string tag
126 it.replaceAll("\\^\\{\\}", '')
129 branches = branches.unique()
132 branches.each { branch ->
133 def stripBranch = branch.replaceAll("rc", '').replaceAll(/refs\/tags\/v/,'')
134 BasicVersion kVersion = new BasicVersion(stripBranch, branch)
135 versions.add(kVersion)
138 // Sort the version via Comparable implementation of KernelVersion
139 versions = versions.sort()
141 // Find the version cutoff
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)}
144 // If error set cutoff on last so no job are created
145 if (cutoffPos == -1) {
146 cutoffPos = versions.size()
148 // Get last version and include only last rc
151 last = versions.last()
153 int i = versions.size()-1
154 while (i > -1 && versions[i].rc != -1 ) {
159 lastNoRcPos = versions.size()
162 String modulesPrefix = "lttng-modules"
163 String kernelPrefix = "dsl-kernel"
164 String separator = "-"
167 println("CutOff index")
171 // Actual job creation
172 for (int i = cutoffPos; i < versions.size() ; i++) {
174 // Only create for valid build
175 if ( (i < lastNoRcPos && versions[i].rc == -1) || (i >= lastNoRcPos)) {
176 println ("Preparing job for")
178 String jobName = kernelPrefix + separator + versions[i].print()
180 // Generate modules job based on supported modules jobs
182 modulesBranches.each { branch ->
183 modulesJob[branch] = modulesPrefix + separator + branch + separator + jobName
188 if (isJenkinsInstance) {
189 matrixJob("${jobName}") {
190 using("linux-master")
196 branch(versions[i].gitRefs)
198 relativeTargetDir(linuxCheckoutTo)
199 reference(linuxGitReference)
204 downstream(it.value, 'SUCCESS')
209 // Corresponding Module job
210 modulesJob.each { job ->
211 println("\t" + job.key + " " + job.value)
212 if (isJenkinsInstance) {
213 matrixJob(job.value) {
221 branch(versions[i].gitRefs)
223 relativeTargetDir(linuxCheckoutTo)
224 reference(linuxGitReference)
232 relativeTargetDir(modulesCheckoutTo)
236 copyArtifacts("${jobName}/arch=\$arch", "linux-artifact/**", '', false, false) {
237 latestSuccessful(true) // Latest successful build
239 shell(readFileFromWorkspace('lttng-modules/lttng-modules-dsl-master.sh'))
247 // Trigger generations
248 def dslTriggerKernel = """\
250 import hudson.model.*
251 import hudson.AbortException
252 import hudson.console.HyperlinkNote
253 import java.util.concurrent.CancellationException
256 def jobs = hudson.model.Hudson.instance.items
258 def jobStartWith = "${kernelPrefix}"
262 def jobName = job.getName()
263 if (jobName.startsWith(jobStartWith)) {
264 def lastBuild = job.getLastBuild()
265 if (lastBuild == null) {
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.")
273 println HyperlinkNote.encodeTo('/' + anotherBuild.url, anotherBuild.fullDisplayName) + " completed. Result was " + anotherBuild.result
275 build.result = anotherBuild.result
276 if (anotherBuild.result != Result.SUCCESS && anotherBuild.result != Result.UNSTABLE) {
277 // We abort this build right here and now.
279 println("Build Failed")
282 println("\\tAlready built")
288 throw new AbortException("Some job failed")
291 def dslTriggerModule = """\
292 import hudson.model.*
293 import hudson.AbortException
294 import hudson.console.HyperlinkNote
295 import java.util.concurrent.CancellationException
298 def jobs = hudson.model.Hudson.instance.items
300 def jobStartWith = "JOBPREFIX"
304 def jobName = job.getName()
305 if (jobName.startsWith(jobStartWith)) {
306 def lastBuild = job.getLastBuild()
307 if (lastBuild == null) {
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.")
315 println HyperlinkNote.encodeTo('/' + anotherBuild.url, anotherBuild.fullDisplayName) + " completed. Result was " + anotherBuild.result
317 build.result = anotherBuild.result
318 if (anotherBuild.result != Result.SUCCESS && anotherBuild.result != Result.UNSTABLE) {
319 // We abort this build right here and now.
321 println("Build Failed")
324 println("\\tAlready built")
330 throw new AbortException("Some job failed")
333 if (isJenkinsInstance) {
334 freeStyleJob("dsl-trigger-kernel") {
336 systemGroovyCommand(dslTriggerKernel)
343 modulesBranches.each { branch ->
344 freeStyleJob("dsl-trigger-module-${branch}") {
346 systemGroovyCommand(dslTriggerModule.replaceAll("JOBPREFIX",modulesPrefix + separator + branch + separator))