Dsl job for kernel lttng-modules job generation
[lttng-ci.git] / dsl / kernel-lttng-modules.seed.groovy
1 import groovy.transform.Sortable
2
3 enum KernelVersioning {
4 MAJOR,MINOR,REVISION,BUILD
5 }
6
7 class KernelVersion implements Comparable<KernelVersion> {
8 int major = -1
9 int minor = -1
10 int revision = -1
11 int build = -1
12 int rc = -1
13
14 // Default Constructor
15 KernelVersion() {}
16
17 // Parse a version string of format X,Y,Z,W-A
18 KernelVersion(String version) {
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
65 String print() {
66 String ret = ""
67 if (major != -1) {
68 ret += major
69 if (minor != -1) {
70 ret += "." + minor
71 if (revision != -1) {
72 ret += "." + revision
73 if (build != -1) {
74 ret += "." + build
75 }
76 }
77 }
78 if (rc != -1) {
79 ret += "-" + rc
80 }
81 }
82 return ret
83 }
84
85 @Override
86 int compareTo(KernelVersion kernelVersion) {
87 return major <=> kernelVersion.major ?: minor <=> kernelVersion.minor ?: revision <=> kernelVersion.revision ?: build <=> kernelVersion.build ?: rc <=> kernelVersion.rc
88 }
89 }
90
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"
94
95 // Linux specific variable
96 String linuxCheckoutTo = "linux-source"
97 String recipeCheckoutTo = "recipe"
98 String modulesCheckoutTo = "lttng-modules"
99
100 def linuxGitReference = "/home/jenkins/gitcache/linux-stable.git"
101 String process = "git ls-remote -t $linuxURL | cut -c42- | sort -V"
102
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')
106
107
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 ->
113 if( p )
114 p | c.execute()
115 else
116 c.execute()
117 }
118
119 result.waitForProcessOutput(out,err)
120
121 if ( result.exitValue() == 0 ) {
122 def branches = out.readLines().collect {
123 it.replaceAll("\\^\\{\\}", '').replaceAll("rc", '').replaceAll(/refs\/tags\/v/,'')
124 }
125
126 branches = branches.unique()
127 List versions = []
128
129 branches.each { branch ->
130 KernelVersion kVersion = new KernelVersion(branch.toString())
131 versions.add(kVersion)
132 }
133
134 // Sort the version
135 versions = versions.sort()
136
137 // Find cut of
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)}
139
140
141 // Get last version and include only last rc
142 def last
143 def lastNoRcPos
144 last = versions.last()
145 if (last.rc != -1) {
146 int i = versions.size()-1
147 while (i > -1 && versions[i].rc != -1 ) {
148 i--
149 }
150 lastNoRcPos = i + 1
151 } else {
152 lastNoRcPos = versions.size()
153 }
154
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}"
161 println(jobName)
162 println(moduleJobName)
163 if (isJenkinsInstance) {
164 matrixJob("${jobName}") {
165 using("linux-master")
166 scm {
167 git {
168 remote {
169 url("${linuxURL}")
170 }
171 branch(tag)
172 shallowClone(true)
173 relativeTargetDir(linuxCheckoutTo)
174 reference(linuxGitReference)
175 }
176 }
177 publishers {
178 downstream(moduleJobName, 'SUCCESS')
179 }
180 }
181 // Corresponding Module job
182 matrixJob("${moduleJobName}") {
183 using("modules")
184 multiscm {
185 git {
186 remote {
187 name("linux")
188 url("${linuxURL}")
189 }
190 branch(tag)
191 shallowClone(true)
192 relativeTargetDir(linuxCheckoutTo)
193 reference(linuxGitReference)
194 }
195 git {
196 remote {
197 name("lttng-modules")
198 url(modulesURL)
199 }
200 branch("master")
201 relativeTargetDir(modulesCheckoutTo)
202 }
203 }
204 steps {
205 copyArtifacts("${jobName}/arch=\$arch", "linux-artifact/**", '', false, false) {
206 latestSuccessful(true) // Latest successful build
207 }
208 shell(readFileFromWorkspace('lttng-modules/lttng-modules-dsl-master.sh'))
209 }
210 }
211 }
212 }
213 }
214 }
215
This page took 0.033218 seconds and 4 git commands to generate.