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.0", "")
91 def modulesBranches = ["master","stable-2.5.0","stable-2.6.0", "stable-2.4.0"]
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"
103 String process = "git ls-remote -t $linuxURL | cut -c42- | sort -V"
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 // Split the string into sections based on |
110 // And pipe the results together
111 def out = new StringBuilder()
112 def err = new StringBuilder()
113 Process result = process.tokenize( '|' ).inject( null ) { p, c ->
120 result.waitForProcessOutput(out,err)
122 if ( result.exitValue() == 0 ) {
123 def branches = out.readLines().collect {
124 // Scrap special string tag
125 it.replaceAll("\\^\\{\\}", '')
128 branches = branches.unique()
131 branches.each { branch ->
132 def stripBranch = branch.replaceAll("rc", '').replaceAll(/refs\/tags\/v/,'')
133 BasicVersion kVersion = new BasicVersion(stripBranch, branch)
134 versions.add(kVersion)
137 // Sort the version via Comparable implementation of KernelVersion
138 versions = versions.sort()
140 // Find the version cut of
141 def cutoffPos = versions.findIndexOf{(it.major >= kernelTagCutOff.major) && (it.minor >= kernelTagCutOff.minor) && (it.revision >= kernelTagCutOff.revision) && (it.build >= kernelTagCutOff.build) && (it.rc >= kernelTagCutOff.rc)}
143 // Get last version and include only last rc
146 last = versions.last()
148 int i = versions.size()-1
149 while (i > -1 && versions[i].rc != -1 ) {
154 lastNoRcPos = versions.size()
157 String modulesPrefix = "lttng-modules"
158 String kernelPrefix = "dsl-kernel"
159 String separator = "-"
160 // Actual job creation
161 for (int i = cutoffPos; i < versions.size() ; i++) {
163 // Only create for valid build
164 if ( (i < lastNoRcPos && versions[i].rc == -1) || (i >= lastNoRcPos)) {
165 println ("Preparing job for")
167 String jobName = kernelPrefix + separator + versions[i].print()
169 // Generate modules job based on supported modules jobs
171 modulesBranches.each { branch ->
172 modulesJob[branch] = modulesPrefix + separator + branch + separator + jobName
177 if (isJenkinsInstance) {
178 matrixJob("${jobName}") {
179 using("linux-master")
185 branch(versions[i].gitRefs)
187 relativeTargetDir(linuxCheckoutTo)
188 reference(linuxGitReference)
193 downstream(it.value, 'SUCCESS')
198 // Corresponding Module job
199 modulesJob.each { job ->
200 println("\t" + job.key + " " + job.value)
201 if (isJenkinsInstance) {
202 matrixJob(job.value) {
210 branch(versions[i].gitRefs)
212 relativeTargetDir(linuxCheckoutTo)
213 reference(linuxGitReference)
221 relativeTargetDir(modulesCheckoutTo)
225 copyArtifacts("${jobName}/arch=\$arch", "linux-artifact/**", '', false, false) {
226 latestSuccessful(true) // Latest successful build
228 shell(readFileFromWorkspace('lttng-modules/lttng-modules-dsl-master.sh'))
236 // Trigger generations
237 def dslTriggerKernel = """\
239 import hudson.model.*
240 import hudson.AbortException
241 import hudson.console.HyperlinkNote
242 import java.util.concurrent.CancellationException
245 def jobs = hudson.model.Hudson.instance.items
247 def jobStartWith = ${kernelPrefix}
251 def jobName = job.getName()
252 if (jobName.startsWith(jobStartWith)) {
253 def lastBuild = job.getLastBuild()
254 if (lastBuild == null) {
256 def future = job.scheduleBuild2(0, new Cause.UpstreamCause(build))
257 println "\\tWaiting for the completion of " + HyperlinkNote.encodeTo('/' + job.url, job.fullDisplayName)
258 anotherBuild = future.get()
259 } catch (CancellationException x) {
260 throw new AbortException("\${job.fullDisplayName} aborted.")
262 println HyperlinkNote.encodeTo('/' + anotherBuild.url, anotherBuild.fullDisplayName) + " completed. Result was " + anotherBuild.result
264 build.result = anotherBuild.result
265 if (anotherBuild.result != Result.SUCCESS && anotherBuild.result != Result.UNSTABLE) {
266 // We abort this build right here and now.
268 println("Build Failed")
271 println("\\tAlready built")
277 throw new AbortException("Some job failed")
280 if (isJenkinsInstance) {
281 freeStyleJob("dsl-trigger-kernel") {
283 systemGroovyCommand(dslTriggerKernel)