2 * Copyright (C) 2017 - Michael Jeanson <mjeanson@efficios.com>
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 import hudson.AbortException
20 import hudson.console.HyperlinkNote
21 import java.util.concurrent.CancellationException
22 import org.eclipse.jgit.api.Git
23 import org.eclipse.jgit.lib.Ref
25 def kgitrepo = "git://git-mirror.internal.efficios.com/git/linux-all.git"
26 def ondiskpath = build.getEnvironment(listener).get('WORKSPACE') + "/ondisk-refs"
29 'lttng-modules_master_build-vanilla',
30 'lttng-modules_stable-2.13_build-vanilla',
31 'lttng-modules_stable-2.12_build-vanilla',
32 'lttng-modules_stable-2.11_build-vanilla',
33 'lttng-modules_stable-2.10_build-vanilla',
34 'lttng-modules_master_crossbuild-vanilla',
35 'lttng-modules_stable-2.13_crossbuild-vanilla',
36 'lttng-modules_stable-2.12_crossbuild-vanilla',
37 'lttng-modules_stable-2.11_crossbuild-vanilla',
38 'lttng-modules_stable-2.10_crossbuild-vanilla',
41 def previous_tags = []
43 def current_tags = [] as Set
45 // First try to load previous tags from disk
47 def input = new ObjectInputStream(new FileInputStream(ondiskpath))
48 previous_tags = input.readObject()
51 println("Failed to load previous tags from disk.")
54 println("Loaded " + previous_tags.size() + " tags from disk.")
55 //println("Previous tags:")
56 //for (tag in previous_tags) {
57 // println(" - ${tag}")
60 // Get current tag refs from git repository
61 current_refs = Git.lsRemoteRepository().setTags(true).setRemote(kgitrepo).call();
63 println("Loaded " + current_refs.size() + " tags from git repository.")
64 //println("Current tags:")
65 for (ref in current_refs) {
66 //println(" - " + ref.getName())
67 current_tags.add(ref.getName())
70 // Write currents tags to disk
72 def out = new ObjectOutputStream(new FileOutputStream(ondiskpath))
73 out.writeObject(current_tags)
76 println("Failed to write tags to disk")
80 //current_tags.add("this_is_a_test")
83 current_tags.removeAll(previous_tags)
85 // If there are new tags, trigger the builds
86 if (current_tags.size() > 0) {
87 println("Found " + current_tags.size() + "new tags:")
88 for (tag in current_tags) {
92 for (jobname in trigger_jobs) {
93 println("Triggering job : ${jobname}")
94 def job = Hudson.instance.getJob(jobname)
97 for (paramdef in job.getProperty(ParametersDefinitionProperty.class).getParameterDefinitions()) {
98 params += paramdef.getDefaultParameterValue();
100 def paramsAction = new hudson.model.ParametersAction(params)
102 def cause = new Cause.UpstreamCause(build)
103 def causeAction = new CauseAction(cause)
105 Hudson.instance.queue.schedule(job, 0, causeAction, paramsAction)
108 println("No new tags, nothing to do.")