test
[lttng-ci.git] / dsl / kernel-lttng-modules.seed.groovy
1 enum KernelVersioning {
2 MAJOR,MINOR,REVISION,BUILD
3 }
4
5 class BasicVersion implements Comparable<BasicVersion> {
6 int major = -1
7 int minor = -1
8 int revision = -1
9 int build = -1
10 int rc = -1
11 String gitRefs
12
13 // Default Constructor
14 BasicVersion() {}
15
16 // Parse a version string of format X.Y.Z.W-A
17 BasicVersion(String version, String ref) {
18 gitRefs = ref
19 def tokenVersion
20 def token
21 if (version.contains('-')) {
22 // Release canditate
23 token = version.tokenize('-')
24 tokenVersion = token[0]
25 if (token[1]?.isInteger()) {
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 {
36 if (it?.isInteger()) {
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}")
58 //TODO: throw exception for jenkins
59 }
60 }
61 }
62 }
63
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) {
78 ret += "-rc" + rc
79 }
80 }
81 return ret
82 }
83
84 @Override
85 int compareTo(BasicVersion kernelVersion) {
86 return major <=> kernelVersion.major ?: minor <=> kernelVersion.minor ?: revision <=> kernelVersion.revision ?: build <=> kernelVersion.build ?: rc <=> kernelVersion.rc
87 }
88 }
89
90 def kernelTagCutOff = new BasicVersion("4.0", "")
91 def modulesBranches = ["master","stable-2.5.0","stable-2.6.0", "stable-2.4.0"]
92
93
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"
96
97 // Linux specific variable
98 String linuxCheckoutTo = "linux-source"
99 String recipeCheckoutTo = "recipe"
100 String modulesCheckoutTo = "lttng-modules"
101
102 def linuxGitReference = "/home/jenkins/gitcache/linux-stable.git"
103 String process = "git ls-remote -t $linuxURL | cut -c42- | sort -V"
104
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')
108
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 ->
114 if( p )
115 p | c.execute()
116 else
117 c.execute()
118 }
119
120 result.waitForProcessOutput(out,err)
121
122 if ( result.exitValue() == 0 ) {
123 def branches = out.readLines().collect {
124 // Scrap special string tag
125 it.replaceAll("\\^\\{\\}", '')
126 }
127
128 branches = branches.unique()
129
130 List versions = []
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)
135 }
136
137 // Sort the version via Comparable implementation of KernelVersion
138 versions = versions.sort()
139
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)}
142
143 // Get last version and include only last rc
144 def last
145 def lastNoRcPos
146 last = versions.last()
147 if (last.rc != -1) {
148 int i = versions.size()-1
149 while (i > -1 && versions[i].rc != -1 ) {
150 i--
151 }
152 lastNoRcPos = i + 1
153 } else {
154 lastNoRcPos = versions.size()
155 }
156
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++) {
162
163 // Only create for valid build
164 if ( (i < lastNoRcPos && versions[i].rc == -1) || (i >= lastNoRcPos)) {
165 println ("Preparing job for")
166
167 String jobName = kernelPrefix + separator + versions[i].print()
168
169 // Generate modules job based on supported modules jobs
170 def modulesJob = [:]
171 modulesBranches.each { branch ->
172 modulesJob[branch] = modulesPrefix + separator + branch + separator + jobName
173 }
174
175 // Jenkins only dsl
176 println(jobName)
177 if (isJenkinsInstance) {
178 matrixJob("${jobName}") {
179 using("linux-master")
180 scm {
181 git {
182 remote {
183 url("${linuxURL}")
184 }
185 branch(versions[i].gitRefs)
186 shallowClone(true)
187 relativeTargetDir(linuxCheckoutTo)
188 reference(linuxGitReference)
189 }
190 }
191 publishers {
192 modulesJob.each {
193 downstream(it.value, 'SUCCESS')
194 }
195 }
196 }
197 }
198 // Corresponding Module job
199 modulesJob.each { job ->
200 println("\t" + job.key + " " + job.value)
201 if (isJenkinsInstance) {
202 matrixJob(job.value) {
203 using("modules")
204 multiscm {
205 git {
206 remote {
207 name(kernelPrefix)
208 url("${linuxURL}")
209 }
210 branch(versions[i].gitRefs)
211 shallowClone(true)
212 relativeTargetDir(linuxCheckoutTo)
213 reference(linuxGitReference)
214 }
215 git {
216 remote {
217 name(modulesPrefix)
218 url(modulesURL)
219 }
220 branch(job.key)
221 relativeTargetDir(modulesCheckoutTo)
222 }
223 }
224 steps {
225 copyArtifacts("${jobName}/arch=\$arch", "linux-artifact/**", '', false, false) {
226 latestSuccessful(true) // Latest successful build
227 }
228 shell(readFileFromWorkspace('lttng-modules/lttng-modules-dsl-master.sh'))
229 }
230 }
231 }
232 }
233 }
234 }
235
236 // Trigger generations
237 def dslTriggerKernel = """\
238
239 import hudson.model.*
240 import hudson.AbortException
241 import hudson.console.HyperlinkNote
242 import java.util.concurrent.CancellationException
243
244
245 def jobs = hudson.model.Hudson.instance.items
246 def fail = false
247 def jobStartWith = "${kernelPrefix}"
248
249 def anotherBuild
250 jobs.each { job ->
251 def jobName = job.getName()
252 if (jobName.startsWith(jobStartWith)) {
253 def lastBuild = job.getLastBuild()
254 if (lastBuild == null) {
255 try {
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.")
261 }
262 println HyperlinkNote.encodeTo('/' + anotherBuild.url, anotherBuild.fullDisplayName) + " completed. Result was " + anotherBuild.result
263
264 build.result = anotherBuild.result
265 if (anotherBuild.result != Result.SUCCESS && anotherBuild.result != Result.UNSTABLE) {
266 // We abort this build right here and now.
267 fail = true
268 println("Build Failed")
269 }
270 } else {
271 println("\\tAlready built")
272 }
273 }
274 }
275
276 if (fail){
277 throw new AbortException("Some job failed")
278 }
279 """
280 if (isJenkinsInstance) {
281 freeStyleJob("dsl-trigger-kernel") {
282 steps {
283 systemGroovyCommand(dslTriggerKernel)
284 }
285 }
286 // Trigger the kernel build
287 def kernel_trigger_job = hudson.model.Hudson.instance.getItem("dsl-trigger-kernel")
288 kernel_trigger_job.scheduleBuild2(0)
289 }
290 }
This page took 0.03566 seconds and 5 git commands to generate.