Debug
[lttng-ci.git] / dsl / kernel-lttng-modules.seed.groovy
CommitLineData
017c762b
JR
1enum KernelVersioning {
2 MAJOR,MINOR,REVISION,BUILD
3}
4
81470b33 5class BasicVersion implements Comparable<BasicVersion> {
017c762b
JR
6 int major = -1
7 int minor = -1
8 int revision = -1
9 int build = -1
10 int rc = -1
5a67a345 11 String gitRefs
017c762b
JR
12
13 // Default Constructor
81470b33 14 BasicVersion() {}
017c762b 15
81470b33
JR
16 // Parse a version string of format X.Y.Z.W-A
17 BasicVersion(String version, String ref) {
5a67a345 18 gitRefs = ref
d11d0665 19 def tokenVersion
017c762b
JR
20 def token
21 if (version.contains('-')) {
22 // Release canditate
23 token = version.tokenize('-')
24 tokenVersion = token[0]
81470b33 25 if (token[1]?.isInteger()) {
017c762b
JR
26 rc = token[1].toInteger()
27 }
28 } else {
29 tokenVersion = version
30 }
31
32 tokenVersion = tokenVersion.tokenize('.')
33
34 def tagEnum = KernelVersioning.MAJOR
35 tokenVersion.each {
81470b33 36 if (it?.isInteger()) {
017c762b
JR
37 switch (tagEnum) {
38 case KernelVersioning.MAJOR:
39 major = it.toInteger()
40 tagEnum = KernelVersioning.MINOR
41 break
42 case KernelVersioning.MINOR:
43 minor = it.toInteger()
44 tagEnum = KernelVersioning.REVISION
45 break
46 case KernelVersioning.REVISION:
47 revision = it.toInteger()
48 tagEnum = KernelVersioning.BUILD
49 break
50 case KernelVersioning.BUILD:
51 build = it.toInteger()
52 tagEnum = -1
53 break
54 default:
55 println("Unsupported version extension")
56 println("Trying to parse: ${version}")
57 println("Invalid sub version value: ${it}")
d11d0665 58 //TODO: throw exception for jenkins
017c762b
JR
59 }
60 }
61 }
62 }
63
017c762b
JR
64 String print() {
65 String ret = ""
66 if (major != -1) {
67 ret += major
68 if (minor != -1) {
69 ret += "." + minor
70 if (revision != -1) {
71 ret += "." + revision
72 if (build != -1) {
73 ret += "." + build
74 }
75 }
76 }
77 if (rc != -1) {
5a67a345 78 ret += "-rc" + rc
017c762b
JR
79 }
80 }
81 return ret
82 }
83
84 @Override
81470b33 85 int compareTo(BasicVersion kernelVersion) {
017c762b
JR
86 return major <=> kernelVersion.major ?: minor <=> kernelVersion.minor ?: revision <=> kernelVersion.revision ?: build <=> kernelVersion.build ?: rc <=> kernelVersion.rc
87 }
88}
89
472505ab
JR
90def kernelTagCutOff = new BasicVersion("4.1", "")
91def modulesBranches = []
d11d0665 92
472505ab 93//def modulesBranches = ["master","stable-2.5","stable-2.6", "stable-2.4"]
d11d0665 94
017c762b
JR
95def linuxURL = "git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git"
96def modulesURL = "git://git.lttng.org/lttng-modules.git"
97
98// Linux specific variable
99String linuxCheckoutTo = "linux-source"
100String recipeCheckoutTo = "recipe"
101String modulesCheckoutTo = "lttng-modules"
102
103def linuxGitReference = "/home/jenkins/gitcache/linux-stable.git"
017c762b 104
d11d0665 105// Check if we are on jenkins
81f87da0
JR
106// Useful for outside jenkins devellopment related to groovy only scripting
107def isJenkinsInstance = binding.variables.containsKey('JENKINS_HOME')
108
132cba4a 109// Fetch tags and format
017c762b
JR
110// Split the string into sections based on |
111// And pipe the results together
132cba4a 112String process = "git ls-remote -t $linuxURL | cut -c42- | sort -V"
017c762b
JR
113def out = new StringBuilder()
114def err = new StringBuilder()
115Process result = process.tokenize( '|' ).inject( null ) { p, c ->
116 if( p )
117 p | c.execute()
118 else
119 c.execute()
120}
121
122result.waitForProcessOutput(out,err)
123
124if ( result.exitValue() == 0 ) {
125 def branches = out.readLines().collect {
d11d0665 126 // Scrap special string tag
5a67a345 127 it.replaceAll("\\^\\{\\}", '')
017c762b
JR
128 }
129
130 branches = branches.unique()
017c762b 131
81f87da0 132 List versions = []
017c762b 133 branches.each { branch ->
d11d0665
JR
134 def stripBranch = branch.replaceAll("rc", '').replaceAll(/refs\/tags\/v/,'')
135 BasicVersion kVersion = new BasicVersion(stripBranch, branch)
017c762b
JR
136 versions.add(kVersion)
137 }
138
81f87da0 139 // Sort the version via Comparable implementation of KernelVersion
017c762b
JR
140 versions = versions.sort()
141
132cba4a 142 // Find the version cutoff
d11d0665 143 def cutoffPos = versions.findIndexOf{(it.major >= kernelTagCutOff.major) && (it.minor >= kernelTagCutOff.minor) && (it.revision >= kernelTagCutOff.revision) && (it.build >= kernelTagCutOff.build) && (it.rc >= kernelTagCutOff.rc)}
017c762b 144
831d4383
JR
145 // If error set cutoff on last so no job are created
146 if (cutoffPos == -1) {
147 cutoffPos = versions.size()
148 }
017c762b
JR
149 // Get last version and include only last rc
150 def last
151 def lastNoRcPos
152 last = versions.last()
153 if (last.rc != -1) {
154 int i = versions.size()-1
155 while (i > -1 && versions[i].rc != -1 ) {
156 i--
157 }
158 lastNoRcPos = i + 1
159 } else {
160 lastNoRcPos = versions.size()
161 }
162
d11d0665 163 String modulesPrefix = "lttng-modules"
162a2360 164 String kernelPrefix = "dsl-kernel"
d11d0665 165 String separator = "-"
831d4383 166
07f90dd7
JR
167
168 println("CutOff index")
169 println(cutoffPos)
170
171
d11d0665 172 // Actual job creation
017c762b 173 for (int i = cutoffPos; i < versions.size() ; i++) {
81f87da0 174
d11d0665 175 // Only create for valid build
017c762b
JR
176 if ( (i < lastNoRcPos && versions[i].rc == -1) || (i >= lastNoRcPos)) {
177 println ("Preparing job for")
d11d0665
JR
178
179 String jobName = kernelPrefix + separator + versions[i].print()
180
181 // Generate modules job based on supported modules jobs
182 def modulesJob = [:]
183 modulesBranches.each { branch ->
184 modulesJob[branch] = modulesPrefix + separator + branch + separator + jobName
185 }
186
187 // Jenkins only dsl
017c762b 188 println(jobName)
d11d0665
JR
189 if (isJenkinsInstance) {
190 matrixJob("${jobName}") {
191 using("linux-master")
192 scm {
193 git {
194 remote {
195 url("${linuxURL}")
196 }
197 branch(versions[i].gitRefs)
198 shallowClone(true)
199 relativeTargetDir(linuxCheckoutTo)
200 reference(linuxGitReference)
201 }
202 }
203 publishers {
204 modulesJob.each {
205 downstream(it.value, 'SUCCESS')
206 }
207 }
208 }
209 }
210 // Corresponding Module job
ef0e4e86
JR
211 modulesJob.each { job ->
212 println("\t" + job.key + " " + job.value)
d11d0665 213 if (isJenkinsInstance) {
ef0e4e86 214 matrixJob(job.value) {
d11d0665
JR
215 using("modules")
216 multiscm {
217 git {
218 remote {
219 name(kernelPrefix)
220 url("${linuxURL}")
221 }
222 branch(versions[i].gitRefs)
223 shallowClone(true)
224 relativeTargetDir(linuxCheckoutTo)
225 reference(linuxGitReference)
226 }
227 git {
228 remote {
229 name(modulesPrefix)
230 url(modulesURL)
231 }
ef0e4e86 232 branch(job.key)
d11d0665
JR
233 relativeTargetDir(modulesCheckoutTo)
234 }
235 }
236 steps {
237 copyArtifacts("${jobName}/arch=\$arch", "linux-artifact/**", '', false, false) {
238 latestSuccessful(true) // Latest successful build
239 }
240 shell(readFileFromWorkspace('lttng-modules/lttng-modules-dsl-master.sh'))
241 }
242 }
243 }
244 }
245 }
246 }
162a2360
JR
247
248 // Trigger generations
249 def dslTriggerKernel = """\
250
251import hudson.model.*
252import hudson.AbortException
253import hudson.console.HyperlinkNote
254import java.util.concurrent.CancellationException
255
256
257def jobs = hudson.model.Hudson.instance.items
258def fail = false
b46e797c 259def jobStartWith = "${kernelPrefix}"
162a2360
JR
260
261def anotherBuild
262jobs.each { job ->
263 def jobName = job.getName()
264 if (jobName.startsWith(jobStartWith)) {
265 def lastBuild = job.getLastBuild()
266 if (lastBuild == null) {
267 try {
268 def future = job.scheduleBuild2(0, new Cause.UpstreamCause(build))
269 println "\\tWaiting for the completion of " + HyperlinkNote.encodeTo('/' + job.url, job.fullDisplayName)
270 anotherBuild = future.get()
271 } catch (CancellationException x) {
272 throw new AbortException("\${job.fullDisplayName} aborted.")
273 }
274 println HyperlinkNote.encodeTo('/' + anotherBuild.url, anotherBuild.fullDisplayName) + " completed. Result was " + anotherBuild.result
275
276 build.result = anotherBuild.result
277 if (anotherBuild.result != Result.SUCCESS && anotherBuild.result != Result.UNSTABLE) {
278 // We abort this build right here and now.
279 fail = true
280 println("Build Failed")
281 }
282 } else {
283 println("\\tAlready built")
284 }
285 }
286}
287
c76d8fe2
JR
288if (fail){
289 throw new AbortException("Some job failed")
290}
291"""
292 def dslTriggerModule = """\
293import hudson.model.*
294import hudson.AbortException
295import hudson.console.HyperlinkNote
296import java.util.concurrent.CancellationException
297
298
299def jobs = hudson.model.Hudson.instance.items
300def fail = false
6a7fce90 301def jobStartWith = "JOBPREFIX"
c76d8fe2
JR
302
303def anotherBuild
304jobs.each { job ->
305 def jobName = job.getName()
306 if (jobName.startsWith(jobStartWith)) {
307 def lastBuild = job.getLastBuild()
308 if (lastBuild == null) {
309 try {
310 def future = job.scheduleBuild2(0, new Cause.UpstreamCause(build))
311 println "\\tWaiting for the completion of " + HyperlinkNote.encodeTo('/' + job.url, job.fullDisplayName)
312 anotherBuild = future.get()
313 } catch (CancellationException x) {
314 throw new AbortException("\${job.fullDisplayName} aborted.")
315 }
316 println HyperlinkNote.encodeTo('/' + anotherBuild.url, anotherBuild.fullDisplayName) + " completed. Result was " + anotherBuild.result
317
318 build.result = anotherBuild.result
319 if (anotherBuild.result != Result.SUCCESS && anotherBuild.result != Result.UNSTABLE) {
320 // We abort this build right here and now.
321 fail = true
322 println("Build Failed")
323 }
324 } else {
325 println("\\tAlready built")
326 }
327 }
328}
329
162a2360
JR
330if (fail){
331 throw new AbortException("Some job failed")
332}
333"""
334 if (isJenkinsInstance) {
335 freeStyleJob("dsl-trigger-kernel") {
336 steps {
6f47f2cd 337 systemGroovyCommand(dslTriggerKernel)
162a2360 338 }
d585fdc4
JR
339 triggers {
340 cron("H 0 * * *")
341 }
c76d8fe2
JR
342 }
343
344 modulesBranches.each { branch ->
345 freeStyleJob("dsl-trigger-module-${branch}") {
346 steps {
6a7fce90 347 systemGroovyCommand(dslTriggerModule.replaceAll("JOBPREFIX",modulesPrefix + separator + branch + separator))
c76d8fe2 348 }
d585fdc4
JR
349 triggers {
350 scm('@daily')
351 }
c76d8fe2
JR
352 }
353 }
162a2360 354 }
017c762b 355}
This page took 0.037542 seconds and 4 git commands to generate.