1 enum KernelVersioning {
2 MAJOR,MINOR,REVISION,BUILD
5 class KernelVersion implements Comparable<KernelVersion> {
12 // Default Constructor
15 // Parse a version string of format X,Y,Z,W-A
16 KernelVersion(String version) {
19 if (version.contains('-')) {
21 token = version.tokenize('-')
22 tokenVersion = token[0]
23 if (token[1].isInteger()) {
24 rc = token[1].toInteger()
27 tokenVersion = version
30 tokenVersion = tokenVersion.tokenize('.')
32 def tagEnum = KernelVersioning.MAJOR
36 case KernelVersioning.MAJOR:
37 major = it.toInteger()
38 tagEnum = KernelVersioning.MINOR
40 case KernelVersioning.MINOR:
41 minor = it.toInteger()
42 tagEnum = KernelVersioning.REVISION
44 case KernelVersioning.REVISION:
45 revision = it.toInteger()
46 tagEnum = KernelVersioning.BUILD
48 case KernelVersioning.BUILD:
49 build = it.toInteger()
53 println("Unsupported version extension")
54 println("Trying to parse: ${version}")
55 println("Invalid sub version value: ${it}")
56 //TODO: throw exception for jenkins
84 int compareTo(KernelVersion kernelVersion) {
85 return major <=> kernelVersion.major ?: minor <=> kernelVersion.minor ?: revision <=> kernelVersion.revision ?: build <=> kernelVersion.build ?: rc <=> kernelVersion.rc
89 def cutoff = [major: 3, minor:19,revision:-1, build:-1, rc:-1]
90 def linuxURL = "git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git"
91 def modulesURL = "git://git.lttng.org/lttng-modules.git"
93 // Linux specific variable
94 String linuxCheckoutTo = "linux-source"
95 String recipeCheckoutTo = "recipe"
96 String modulesCheckoutTo = "lttng-modules"
98 def linuxGitReference = "/home/jenkins/gitcache/linux-stable.git"
99 String process = "git ls-remote -t $linuxURL | cut -c42- | sort -V"
101 // Check if we run the script on a jenkins instance
102 // This is useful for dev and debug locally on groovy feature and not jenkins specific stuff
103 def isJenkinsInstance = binding.variables.containsKey('JENKINS_HOME')
106 // Split the string into sections based on |
107 // And pipe the results together
108 def out = new StringBuilder()
109 def err = new StringBuilder()
110 Process result = process.tokenize( '|' ).inject( null ) { p, c ->
117 result.waitForProcessOutput(out,err)
119 if ( result.exitValue() == 0 ) {
120 def branches = out.readLines().collect {
121 it.replaceAll("\\^\\{\\}", '').replaceAll("rc", '').replaceAll(/refs\/tags\/v/,'')
124 branches = branches.unique()
127 branches.each { branch ->
128 KernelVersion kVersion = new KernelVersion(branch.toString())
129 versions.add(kVersion)
133 versions = versions.sort()
136 def cutoffPos = versions.findIndexOf{(it.major >= cutoff.major) && (it.minor >= cutoff.minor) && (it.revision >= cutoff.revision) && (it.build >= cutoff.build) && (it.rc >= cutoff.rc)}
139 // Get last version and include only last rc
142 last = versions.last()
144 int i = versions.size()-1
145 while (i > -1 && versions[i].rc != -1 ) {
150 lastNoRcPos = versions.size()
153 for (int i = cutoffPos; i < versions.size() ; i++) {
154 if ( (i < lastNoRcPos && versions[i].rc == -1) || (i >= lastNoRcPos)) {
155 println ("Preparing job for")
156 String kernel = versions[i].print()
157 String jobName = "kernel-${kernel}"
158 String moduleJobName = "lttng-modules-master-kernel-${kernel}"
160 println(moduleJobName)
161 if (isJenkinsInstance) {
162 matrixJob("${jobName}") {
163 using("linux-master")
171 relativeTargetDir(linuxCheckoutTo)
172 reference(linuxGitReference)
176 downstream(moduleJobName, 'SUCCESS')
179 // Corresponding Module job
180 matrixJob("${moduleJobName}") {
190 relativeTargetDir(linuxCheckoutTo)
191 reference(linuxGitReference)
195 name("lttng-modules")
199 relativeTargetDir(modulesCheckoutTo)
203 copyArtifacts("${jobName}/arch=\$arch", "linux-artifact/**", '', false, false) {
204 latestSuccessful(true) // Latest successful build
206 shell(readFileFromWorkspace('lttng-modules/lttng-modules-dsl-master.sh'))