From 9e5c099a58abcc08e47f7d454df1fab11d4bce1a Mon Sep 17 00:00:00 2001 From: Michael Jeanson Date: Mon, 1 May 2017 18:15:02 -0400 Subject: [PATCH] jjb: Add lttng-modules trigger job Signed-off-by: Michael Jeanson --- jobs/lttng-modules.yaml | 28 +++++ scripts/lttng-modules/trigger-vanilla.groovy | 107 +++++++++++++++++++ 2 files changed, 135 insertions(+) create mode 100644 scripts/lttng-modules/trigger-vanilla.groovy diff --git a/jobs/lttng-modules.yaml b/jobs/lttng-modules.yaml index 0df201a..3d39884 100644 --- a/jobs/lttng-modules.yaml +++ b/jobs/lttng-modules.yaml @@ -151,6 +151,33 @@ ## 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. + +

Job is managed by Jenkins Job Builder.

+ + 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 @@ -535,6 +562,7 @@ 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 index 0000000..2a4cb84 --- /dev/null +++ b/scripts/lttng-modules/trigger-vanilla.groovy @@ -0,0 +1,107 @@ +/** + * Copyright (C) 2017 - Michael Jeanson + * + * 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 . + */ + +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 -- 2.34.1