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("3.0", "")
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 // Get last version and include only last rc
147 last = versions.last()
149 int i = versions.size()-1
150 while (i > -1 && versions[i].rc != -1 ) {
155 lastNoRcPos = versions.size()
158 String modulesPrefix = "lttng-modules"
159 String kernelPrefix = "dsl-kernel"
160 String separator = "-"
161 // Actual job creation
162 for (int i = cutoffPos; i < versions.size() ; i++) {
164 // Only create for valid build
165 if ( (i < lastNoRcPos && versions[i].rc == -1) || (i >= lastNoRcPos)) {
166 println ("Preparing job for")
168 String jobName = kernelPrefix + separator + versions[i].print()
170 // Generate modules job based on supported modules jobs
172 modulesBranches.each { branch ->
173 modulesJob[branch] = modulesPrefix + separator + branch + separator + jobName
178 if (isJenkinsInstance) {
179 matrixJob("${jobName}") {
180 using("linux-master")
186 branch(versions[i].gitRefs)
188 relativeTargetDir(linuxCheckoutTo)
189 reference(linuxGitReference)
194 downstream(it.value, 'SUCCESS')
199 // Corresponding Module job
200 modulesJob.each { job ->
201 println("\t" + job.key + " " + job.value)
202 if (isJenkinsInstance) {
203 matrixJob(job.value) {
211 branch(versions[i].gitRefs)
213 relativeTargetDir(linuxCheckoutTo)
214 reference(linuxGitReference)
222 relativeTargetDir(modulesCheckoutTo)
226 copyArtifacts("${jobName}/arch=\$arch", "linux-artifact/**", '', false, false) {
227 latestSuccessful(true) // Latest successful build
229 shell(readFileFromWorkspace('lttng-modules/lttng-modules-dsl-master.sh'))
237 // Trigger generations
238 def dslTriggerKernel = """\
240 import hudson.model.*
241 import hudson.AbortException
242 import hudson.console.HyperlinkNote
243 import java.util.concurrent.CancellationException
246 def jobs = hudson.model.Hudson.instance.items
248 def jobStartWith = "${kernelPrefix}"
252 def jobName = job.getName()
253 if (jobName.startsWith(jobStartWith)) {
254 def lastBuild = job.getLastBuild()
255 if (lastBuild == null) {
257 def future = job.scheduleBuild2(0, new Cause.UpstreamCause(build))
258 println "\\tWaiting for the completion of " + HyperlinkNote.encodeTo('/' + job.url, job.fullDisplayName)
259 anotherBuild = future.get()
260 } catch (CancellationException x) {
261 throw new AbortException("\${job.fullDisplayName} aborted.")
263 println HyperlinkNote.encodeTo('/' + anotherBuild.url, anotherBuild.fullDisplayName) + " completed. Result was " + anotherBuild.result
265 build.result = anotherBuild.result
266 if (anotherBuild.result != Result.SUCCESS && anotherBuild.result != Result.UNSTABLE) {
267 // We abort this build right here and now.
269 println("Build Failed")
272 println("\\tAlready built")
278 throw new AbortException("Some job failed")
281 def dslTriggerModule = """\
282 import hudson.model.*
283 import hudson.AbortException
284 import hudson.console.HyperlinkNote
285 import java.util.concurrent.CancellationException
288 def jobs = hudson.model.Hudson.instance.items
290 def jobStartWith = "JOBPREFIX"
294 def jobName = job.getName()
295 if (jobName.startsWith(jobStartWith)) {
296 def lastBuild = job.getLastBuild()
297 if (lastBuild == null) {
299 def future = job.scheduleBuild2(0, new Cause.UpstreamCause(build))
300 println "\\tWaiting for the completion of " + HyperlinkNote.encodeTo('/' + job.url, job.fullDisplayName)
301 anotherBuild = future.get()
302 } catch (CancellationException x) {
303 throw new AbortException("\${job.fullDisplayName} aborted.")
305 println HyperlinkNote.encodeTo('/' + anotherBuild.url, anotherBuild.fullDisplayName) + " completed. Result was " + anotherBuild.result
307 build.result = anotherBuild.result
308 if (anotherBuild.result != Result.SUCCESS && anotherBuild.result != Result.UNSTABLE) {
309 // We abort this build right here and now.
311 println("Build Failed")
314 println("\\tAlready built")
320 throw new AbortException("Some job failed")
323 if (isJenkinsInstance) {
324 freeStyleJob("dsl-trigger-kernel") {
326 systemGroovyCommand(dslTriggerKernel)
330 modulesBranches.each { branch ->
331 freeStyleJob("dsl-trigger-module-${branch}") {
333 systemGroovyCommand(dslTriggerModule.replaceAll("JOBPREFIX",modulesPrefix + separator + branch + separator))