jjb: Add lttng-modules trigger job
authorMichael Jeanson <mjeanson@efficios.com>
Mon, 1 May 2017 22:15:02 +0000 (18:15 -0400)
committerMichael Jeanson <mjeanson@efficios.com>
Mon, 1 May 2017 22:15:02 +0000 (18:15 -0400)
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
jobs/lttng-modules.yaml
scripts/lttng-modules/trigger-vanilla.groovy [new file with mode: 0644]

index 0df201ae96a1ea1cb8eeede3b9707c5a5b55c053..3d398843807eb402cccae77a6b2f5654dd950278 100644 (file)
 
 
 ## Templates
+- job-template:
+    name: lttng-modules_ALL_trigger-vanilla
+    defaults: lttng-modules
+    description: |
+      The LTTng modules provide Linux kernel tracing capability to the LTTng
+      2.0 tracer toolset.
+
+      This job will trigger the build jobs when a new tag is added to the vanilla
+      and stable kernel trees.
+
+      <p>Job is managed by Jenkins Job Builder.</p>
+
+    node: 'master'
+
+    wrappers:
+      - timestamps
+      - ansicolor
+
+    scm: []
+
+    builders:
+      - system-groovy:
+         command:
+           !include-raw-escape: scripts/lttng-modules/trigger-vanilla.groovy
+
+    publishers: []
+
 - job-template:
     name: lttng-modules_{mversion}_{buildtype}-vanilla
     defaults: lttng-modules
           cross_arch: !!python/tuple [armhf, arm64, powerpc, ppc64el]
 
 # Misc jobs
+      - 'lttng-modules_ALL_trigger-vanilla'
       - 'lttng-modules_{mversion}_cppcheck':
           mversion:
             - stable-2.8
diff --git a/scripts/lttng-modules/trigger-vanilla.groovy b/scripts/lttng-modules/trigger-vanilla.groovy
new file mode 100644 (file)
index 0000000..2a4cb84
--- /dev/null
@@ -0,0 +1,107 @@
+/**
+ * Copyright (C) 2017 - Michael Jeanson <mjeanson@efficios.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+import hudson.model.*
+import hudson.AbortException
+import hudson.console.HyperlinkNote
+import java.util.concurrent.CancellationException
+import org.eclipse.jgit.api.Git
+import org.eclipse.jgit.lib.Ref
+
+def kgitrepo = "git://git-mirror.internal.efficios.com/git/linux-all.git"
+def ondiskpath = build.getEnvironment(listener).get('WORKSPACE') + "/ondisk-refs"
+
+def trigger_jobs = [
+  'lttng-modules_master_build-vanilla',
+  'lttng-modules_stable-2.9_build-vanilla',
+  'lttng-modules_stable-2.8_build-vanilla',
+  'lttng-modules_master_crossbuild-vanilla',
+  'lttng-modules_stable-2.9_crossbuild-vanilla',
+  'lttng-modules_stable-2.8_crossbuild-vanilla',
+]
+
+def previous_tags = []
+def current_refs = []
+def current_tags = [] as Set
+
+// First try to load previous tags from disk
+try {
+  def input = new ObjectInputStream(new FileInputStream(ondiskpath))
+  previous_tags = input.readObject()
+  input.close()
+} catch (all) {
+  println("Failed to load previous tags from disk.")
+}
+
+println("Loaded " + previous_tags.size() + " tags from disk.")
+//println("Previous tags:")
+//for (tag in previous_tags) {
+//  println(" - ${tag}")
+//}
+
+// Get current tag refs from git repository
+current_refs = Git.lsRemoteRepository().setTags(true).setRemote(kgitrepo).call();
+
+println("Loaded " + current_refs.size() + " tags from git repository.")
+//println("Current tags:")
+for (ref in current_refs) {
+  //println(" - " + ref.getName())
+  current_tags.add(ref.getName())
+}
+
+// Write currents tags to disk
+try {
+  def out = new ObjectOutputStream(new FileOutputStream(ondiskpath))
+  out.writeObject(current_tags)
+  out.close()
+} catch (all) {
+  println("Failed to write tags to disk")
+}
+
+// Debug
+//current_tags.add("this_is_a_test")
+
+// Compare tags
+current_tags.removeAll(previous_tags)
+
+// If there are new tags, trigger the builds
+if (current_tags.size() > 0) {
+  println("Found " + current_tags.size() + "new tags:")
+  for (tag in current_tags) {
+    println(" - ${tag}")
+  }
+
+  for (jobname in trigger_jobs) {
+    println("Triggering job : ${jobname}")
+    def job = Hudson.instance.getJob(jobname)
+
+    def params = [];
+    for (paramdef in job.getProperty(ParametersDefinitionProperty.class).getParameterDefinitions()) {
+      params += paramdef.getDefaultParameterValue();
+    }
+    def paramsAction = new hudson.model.ParametersAction(params)
+
+    def cause = new Cause.UpstreamCause(build)
+    def causeAction = new CauseAction(cause)
+
+    Hudson.instance.queue.schedule(job, 0, causeAction, paramsAction)
+  }
+} else {
+  println("No new tags, nothing to do.")
+}
+
+// EOF
This page took 0.024526 seconds and 4 git commands to generate.