1 import groovy.transform.Sortable
3 enum KernelVersioning {
4 MAJOR,MINOR,REVISION,BUILD
7 class KernelVersion implements Comparable<KernelVersion> {
14 // Default Constructor
17 // Parse a version string of format X,Y,Z,W-A
18 KernelVersion(String version) {
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
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
86 int compareTo(KernelVersion kernelVersion) {
87 return major <=> kernelVersion.major ?: minor <=> kernelVersion.minor ?: revision <=> kernelVersion.revision ?: build <=> kernelVersion.build ?: rc <=> kernelVersion.rc
91 def cutoff = [major: 3, minor:19,revision:-1, build:-1, rc:-1]
92 def linuxURL = "git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git"
93 def modulesURL = "git://git.lttng.org/lttng-modules.git"
95 // Linux specific variable
96 String linuxCheckoutTo = "linux-source"
97 String recipeCheckoutTo = "recipe"
98 String modulesCheckoutTo = "lttng-modules"
100 def linuxGitReference = "/home/jenkins/gitcache/linux-stable.git"
101 String process = "git ls-remote -t $linuxURL | cut -c42- | sort -V"
103 // Check if we run the script on a jenkins instance
104 // This is useful for dev and debug locally on groovy feature and not jenkins specific stuff
105 def isJenkinsInstance = binding.variables.containsKey('JENKINS_HOME')
108 // Split the string into sections based on |
109 // And pipe the results together
110 def out = new StringBuilder()
111 def err = new StringBuilder()
112 Process result = process.tokenize( '|' ).inject( null ) { p, c ->
119 result.waitForProcessOutput(out,err)
121 if ( result.exitValue() == 0 ) {
122 def branches = out.readLines().collect {
123 it.replaceAll("\\^\\{\\}", '').replaceAll("rc", '').replaceAll(/refs\/tags\/v/,'')
126 branches = branches.unique()
129 branches.each { branch ->
130 KernelVersion kVersion = new KernelVersion(branch.toString())
131 versions.add(kVersion)
135 versions = versions.sort()
138 def cutoffPos = versions.findIndexOf{(it.major >= cutoff.major) && (it.minor >= cutoff.minor) && (it.revision >= cutoff.revision) && (it.build >= cutoff.build) && (it.rc >= cutoff.rc)}
141 // Get last version and include only last rc
144 last = versions.last()
146 int i = versions.size()-1
147 while (i > -1 && versions[i].rc != -1 ) {
152 lastNoRcPos = versions.size()
155 for (int i = cutoffPos; i < versions.size() ; i++) {
156 if ( (i < lastNoRcPos && versions[i].rc == -1) || (i >= lastNoRcPos)) {
157 println ("Preparing job for")
158 String kernel = versions[i].print()
159 String jobName = "kernel-${kernel}"
160 String moduleJobName = "lttng-modules-master-kernel-${kernel}"
162 println(moduleJobName)
163 if (isJenkinsInstance) {
164 matrixJob("${jobName}") {
165 using("linux-master")
173 relativeTargetDir(linuxCheckoutTo)
174 reference(linuxGitReference)
178 downstream(moduleJobName, 'SUCCESS')
181 // Corresponding Module job
182 matrixJob("${moduleJobName}") {
192 relativeTargetDir(linuxCheckoutTo)
193 reference(linuxGitReference)
197 name("lttng-modules")
201 relativeTargetDir(modulesCheckoutTo)
205 copyArtifacts("${jobName}/arch=\$arch", "linux-artifact/**", '', false, false) {
206 latestSuccessful(true) // Latest successful build
208 shell(readFileFromWorkspace('lttng-modules/lttng-modules-dsl-master.sh'))