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
91 def kernelTagCutOff = new BasicVersion("3.0", "")
92 def modulesBranches = ["master","stable-2.5","stable-2.6", "stable-2.4"]
94 def kernelTagCutOff = new BasicVersion("4.0", "")
95 def modulesBranches = ["master","stable-2.5.0","stable-2.6.0", "stable-2.4.0"]
96 >>>>>>> parent of badc51e... demo
99 def linuxURL = "git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git"
100 def modulesURL = "git://git.lttng.org/lttng-modules.git"
102 // Linux specific variable
103 String linuxCheckoutTo = "linux-source"
104 String recipeCheckoutTo = "recipe"
105 String modulesCheckoutTo = "lttng-modules"
107 def linuxGitReference = "/home/jenkins/gitcache/linux-stable.git"
109 // Check if we are on jenkins
110 // Useful for outside jenkins devellopment related to groovy only scripting
111 def isJenkinsInstance = binding.variables.containsKey('JENKINS_HOME')
113 // Fetch tags and format
114 // Split the string into sections based on |
115 // And pipe the results together
116 String process = "git ls-remote -t $linuxURL | cut -c42- | sort -V"
117 def out = new StringBuilder()
118 def err = new StringBuilder()
119 Process result = process.tokenize( '|' ).inject( null ) { p, c ->
126 result.waitForProcessOutput(out,err)
128 if ( result.exitValue() == 0 ) {
129 def branches = out.readLines().collect {
130 // Scrap special string tag
131 it.replaceAll("\\^\\{\\}", '')
134 branches = branches.unique()
137 branches.each { branch ->
138 def stripBranch = branch.replaceAll("rc", '').replaceAll(/refs\/tags\/v/,'')
139 BasicVersion kVersion = new BasicVersion(stripBranch, branch)
140 versions.add(kVersion)
143 // Sort the version via Comparable implementation of KernelVersion
144 versions = versions.sort()
146 // Find the version cutoff
147 def cutoffPos = versions.findIndexOf{(it.major >= kernelTagCutOff.major) && (it.minor >= kernelTagCutOff.minor) && (it.revision >= kernelTagCutOff.revision) && (it.build >= kernelTagCutOff.build) && (it.rc >= kernelTagCutOff.rc)}
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 = "-"
166 // Actual job creation
167 for (int i = cutoffPos; i < versions.size() ; i++) {
169 // Only create for valid build
170 if ( (i < lastNoRcPos && versions[i].rc == -1) || (i >= lastNoRcPos)) {
171 println ("Preparing job for")
173 String jobName = kernelPrefix + separator + versions[i].print()
175 // Generate modules job based on supported modules jobs
177 modulesBranches.each { branch ->
178 modulesJob[branch] = modulesPrefix + separator + branch + separator + jobName
183 if (isJenkinsInstance) {
184 matrixJob("${jobName}") {
185 using("linux-master")
191 branch(versions[i].gitRefs)
193 relativeTargetDir(linuxCheckoutTo)
194 reference(linuxGitReference)
199 downstream(it.value, 'SUCCESS')
204 // Corresponding Module job
205 modulesJob.each { job ->
206 println("\t" + job.key + " " + job.value)
207 if (isJenkinsInstance) {
208 matrixJob(job.value) {
216 branch(versions[i].gitRefs)
218 relativeTargetDir(linuxCheckoutTo)
219 reference(linuxGitReference)
227 relativeTargetDir(modulesCheckoutTo)
231 copyArtifacts("${jobName}/arch=\$arch", "linux-artifact/**", '', false, false) {
232 latestSuccessful(true) // Latest successful build
234 shell(readFileFromWorkspace('lttng-modules/lttng-modules-dsl-master.sh'))
242 // Trigger generations
243 def dslTriggerKernel = """\
245 import hudson.model.*
246 import hudson.AbortException
247 import hudson.console.HyperlinkNote
248 import java.util.concurrent.CancellationException
251 def jobs = hudson.model.Hudson.instance.items
253 def jobStartWith = "${kernelPrefix}"
257 def jobName = job.getName()
258 if (jobName.startsWith(jobStartWith)) {
259 def lastBuild = job.getLastBuild()
260 if (lastBuild == null) {
262 def future = job.scheduleBuild2(0, new Cause.UpstreamCause(build))
263 println "\\tWaiting for the completion of " + HyperlinkNote.encodeTo('/' + job.url, job.fullDisplayName)
264 anotherBuild = future.get()
265 } catch (CancellationException x) {
266 throw new AbortException("\${job.fullDisplayName} aborted.")
268 println HyperlinkNote.encodeTo('/' + anotherBuild.url, anotherBuild.fullDisplayName) + " completed. Result was " + anotherBuild.result
270 build.result = anotherBuild.result
271 if (anotherBuild.result != Result.SUCCESS && anotherBuild.result != Result.UNSTABLE) {
272 // We abort this build right here and now.
274 println("Build Failed")
277 println("\\tAlready built")
283 throw new AbortException("Some job failed")
286 def dslTriggerModule = """\
287 import hudson.model.*
288 import hudson.AbortException
289 import hudson.console.HyperlinkNote
290 import java.util.concurrent.CancellationException
293 def jobs = hudson.model.Hudson.instance.items
295 def jobStartWith = "JOBPREFIX"
299 def jobName = job.getName()
300 if (jobName.startsWith(jobStartWith)) {
301 def lastBuild = job.getLastBuild()
302 if (lastBuild == null) {
304 def future = job.scheduleBuild2(0, new Cause.UpstreamCause(build))
305 println "\\tWaiting for the completion of " + HyperlinkNote.encodeTo('/' + job.url, job.fullDisplayName)
306 anotherBuild = future.get()
307 } catch (CancellationException x) {
308 throw new AbortException("\${job.fullDisplayName} aborted.")
310 println HyperlinkNote.encodeTo('/' + anotherBuild.url, anotherBuild.fullDisplayName) + " completed. Result was " + anotherBuild.result
312 build.result = anotherBuild.result
313 if (anotherBuild.result != Result.SUCCESS && anotherBuild.result != Result.UNSTABLE) {
314 // We abort this build right here and now.
316 println("Build Failed")
319 println("\\tAlready built")
325 throw new AbortException("Some job failed")
328 if (isJenkinsInstance) {
329 freeStyleJob("dsl-trigger-kernel") {
331 systemGroovyCommand(dslTriggerKernel)
335 modulesBranches.each { branch ->
336 freeStyleJob("dsl-trigger-module-${branch}") {
338 systemGroovyCommand(dslTriggerModule.replaceAll("JOBPREFIX",modulesPrefix + separator + branch + separator))