Check for if running on jenkins
[lttng-ci.git] / dsl / kernel-lttng-modules.seed.groovy
index 03cfcc25a0f4f61f36314a608506c016c649fa97..6096fd4860a557c49dc3e30ff95fc81ab70ca99e 100644 (file)
@@ -1,5 +1,3 @@
-import groovy.transform.Sortable
-
 enum KernelVersioning {
     MAJOR,MINOR,REVISION,BUILD
 }
@@ -10,13 +8,15 @@ class KernelVersion implements Comparable<KernelVersion> {
     int revision = -1
     int build = -1
     int rc = -1
+    String gitRefs
 
     // Default Constructor
     KernelVersion() {}
 
     // Parse a version string of format X,Y,Z,W-A
-    KernelVersion(String version) {
-        def tokenVersion
+    KernelVersion(String version, String ref) {
+        gitRefs = ref
+               def tokenVersion
         def token
         if (version.contains('-')) {
             // Release canditate
@@ -76,7 +76,7 @@ class KernelVersion implements Comparable<KernelVersion> {
                 }
             }
             if (rc != -1) {
-                ret += "-" + rc
+                ret += "-rc" + rc
             }
         }
         return ret
@@ -88,7 +88,7 @@ class KernelVersion implements Comparable<KernelVersion> {
     }
 }
 
-def cutoff = [major: 3, minor:19,revision:-1, build:-1, rc:-1]
+def cutoff = [major: 3, minor: 19,revision:-1, build:-1, rc:-1]
 def linuxURL = "git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git"
 def modulesURL = "git://git.lttng.org/lttng-modules.git"
 
@@ -100,11 +100,10 @@ String modulesCheckoutTo = "lttng-modules"
 def linuxGitReference = "/home/jenkins/gitcache/linux-stable.git"
 String process = "git ls-remote -t $linuxURL | cut -c42- | sort -V"
 
-// Check if we run the script on a jenkins instance
-// This is useful for dev and debug locally on groovy feature and not jenkins specific stuff
+// Chekf if we are on jenkins
+// Useful for outside jenkins devellopment related to groovy only scripting
 def isJenkinsInstance = binding.variables.containsKey('JENKINS_HOME')
 
-
 // Split the string into sections based on |
 // And pipe the results together
 def out = new StringBuilder()
@@ -120,24 +119,25 @@ result.waitForProcessOutput(out,err)
 
 if ( result.exitValue() == 0 ) {
     def branches = out.readLines().collect {
-        it.replaceAll("\\^\\{\\}", '').replaceAll("rc", '').replaceAll(/refs\/tags\/v/,'')
+               // Scrap special string tag
+        it.replaceAll("\\^\\{\\}", '')
     }
 
     branches = branches.unique()
-    List versions = []
 
+    List versions = []
     branches.each { branch ->
-        KernelVersion kVersion = new KernelVersion(branch.toString())
+               def stripBranch = branch.replaceAll("rc", '').replaceAll(/refs\/tags\/v/,'')
+        KernelVersion kVersion = new KernelVersion(stripBranch, branch)
         versions.add(kVersion)
     }
 
-    // Sort the version
+    // Sort the version via Comparable implementation of KernelVersion
     versions = versions.sort()
 
-    // Find cut of
+    // Find the version cut of
     def cutoffPos = versions.findIndexOf{(it.major >= cutoff.major) && (it.minor >= cutoff.minor) && (it.revision >= cutoff.revision) && (it.build >= cutoff.build) && (it.rc >= cutoff.rc)}
 
-
     // Get last version and include only last rc
     def last
     def lastNoRcPos
@@ -152,7 +152,10 @@ if ( result.exitValue() == 0 ) {
         lastNoRcPos = versions.size()
     }
 
+       // Actual job creation
     for (int i = cutoffPos; i < versions.size() ; i++) {
+
+               // Only create for valid build
         if ( (i < lastNoRcPos && versions[i].rc == -1) || (i >= lastNoRcPos)) {
             println ("Preparing job for")
             String kernel = versions[i].print()
@@ -160,56 +163,57 @@ if ( result.exitValue() == 0 ) {
             String moduleJobName = "lttng-modules-master-kernel-${kernel}"
             println(jobName)
             println(moduleJobName)
-        if (isJenkinsInstance) {
-            matrixJob("${jobName}") {
-                using("linux-master")
-                scm {
-                    git {
-                        remote {
-                            url("${linuxURL}")
-                        }
-                        branch(tag)
-                        shallowClone(true)
-                        relativeTargetDir(linuxCheckoutTo)
-                        reference(linuxGitReference)
-                    }
-                }
-                publishers {
-                    downstream(moduleJobName, 'SUCCESS')
-                }
-            }
-            // Corresponding Module job
-            matrixJob("${moduleJobName}") {
-                using("modules")
-                multiscm {
-                    git {
-                        remote {
-                            name("linux")
-                            url("${linuxURL}")
-                        }
-                        branch(tag)
-                        shallowClone(true)
-                        relativeTargetDir(linuxCheckoutTo)
-                        reference(linuxGitReference)
-                    }
-                    git {
-                        remote {
-                            name("lttng-modules")
-                            url(modulesURL)
-                        }
-                        branch("master")
-                        relativeTargetDir(modulesCheckoutTo)
-                    }
-                }
-                steps {
-                    copyArtifacts("${jobName}/arch=\$arch", "linux-artifact/**", '', false, false) {
-                        latestSuccessful(true) // Latest successful build
-                    }
-                    shell(readFileFromWorkspace('lttng-modules/lttng-modules-dsl-master.sh'))
-                }
-            }
-        }
-        }
-    }
-}
 
+                       // Jenkins only dsl
+                       if (isJenkinsInstance) {
+                               matrixJob("${jobName}") {
+                                       using("linux-master")
+                                               scm {
+                                                       git {
+                                                               remote {
+                                                                       url("${linuxURL}")
+                                                               }
+                                                               branch(versions[i].gitRefs)
+                                                                       shallowClone(true)
+                                                                       relativeTargetDir(linuxCheckoutTo)
+                                                                       reference(linuxGitReference)
+                                                       }
+                                               }
+                                       publishers {
+                                               downstream(moduleJobName, 'SUCCESS')
+                                       }
+                               }
+                               // Corresponding Module job
+                               matrixJob("${moduleJobName}") {
+                                       using("modules")
+                                               multiscm {
+                                                       git {
+                                                               remote {
+                                                                       name("linux")
+                                                                               url("${linuxURL}")
+                                                               }
+                                                               branch(versions[i].gitRefs)
+                                                                       shallowClone(true)
+                                                                       relativeTargetDir(linuxCheckoutTo)
+                                                                       reference(linuxGitReference)
+                                                       }
+                                                       git {
+                                                               remote {
+                                                                       name("lttng-modules")
+                                                                               url(modulesURL)
+                                                               }
+                                                               branch("master")
+                                                                       relativeTargetDir(modulesCheckoutTo)
+                                                       }
+                                               }
+                                       steps {
+                                               copyArtifacts("${jobName}/arch=\$arch", "linux-artifact/**", '', false, false) {
+                                                       latestSuccessful(true) // Latest successful build
+                                               }
+                                               shell(readFileFromWorkspace('lttng-modules/lttng-modules-dsl-master.sh'))
+                                       }
+                               }
+                       }
+               }
+       }
+}
This page took 0.031377 seconds and 4 git commands to generate.