Commit | Line | Data |
---|---|---|
9e5c099a MJ |
1 | /** |
2 | * Copyright (C) 2017 - Michael Jeanson <mjeanson@efficios.com> | |
3 | * | |
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. | |
8 | * | |
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. | |
13 | * | |
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/>. | |
16 | */ | |
17 | ||
18 | import hudson.model.* | |
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 | |
24 | ||
25 | def kgitrepo = "git://git-mirror.internal.efficios.com/git/linux-all.git" | |
26 | def ondiskpath = build.getEnvironment(listener).get('WORKSPACE') + "/ondisk-refs" | |
27 | ||
28 | def trigger_jobs = [ | |
29 | 'lttng-modules_master_build-vanilla', | |
8be4ddf2 | 30 | 'lttng-modules_stable-2.12_build-vanilla', |
7f5ffb7a | 31 | 'lttng-modules_stable-2.11_build-vanilla', |
bb368cde | 32 | 'lttng-modules_stable-2.10_build-vanilla', |
9e5c099a | 33 | 'lttng-modules_master_crossbuild-vanilla', |
8be4ddf2 | 34 | 'lttng-modules_stable-2.12_crossbuild-vanilla', |
7f5ffb7a | 35 | 'lttng-modules_stable-2.11_crossbuild-vanilla', |
bb368cde | 36 | 'lttng-modules_stable-2.10_crossbuild-vanilla', |
9e5c099a MJ |
37 | ] |
38 | ||
39 | def previous_tags = [] | |
40 | def current_refs = [] | |
41 | def current_tags = [] as Set | |
42 | ||
43 | // First try to load previous tags from disk | |
44 | try { | |
45 | def input = new ObjectInputStream(new FileInputStream(ondiskpath)) | |
46 | previous_tags = input.readObject() | |
47 | input.close() | |
48 | } catch (all) { | |
49 | println("Failed to load previous tags from disk.") | |
50 | } | |
51 | ||
52 | println("Loaded " + previous_tags.size() + " tags from disk.") | |
53 | //println("Previous tags:") | |
54 | //for (tag in previous_tags) { | |
55 | // println(" - ${tag}") | |
56 | //} | |
57 | ||
58 | // Get current tag refs from git repository | |
59 | current_refs = Git.lsRemoteRepository().setTags(true).setRemote(kgitrepo).call(); | |
60 | ||
61 | println("Loaded " + current_refs.size() + " tags from git repository.") | |
62 | //println("Current tags:") | |
63 | for (ref in current_refs) { | |
64 | //println(" - " + ref.getName()) | |
65 | current_tags.add(ref.getName()) | |
66 | } | |
67 | ||
68 | // Write currents tags to disk | |
69 | try { | |
70 | def out = new ObjectOutputStream(new FileOutputStream(ondiskpath)) | |
71 | out.writeObject(current_tags) | |
72 | out.close() | |
73 | } catch (all) { | |
74 | println("Failed to write tags to disk") | |
75 | } | |
76 | ||
77 | // Debug | |
78 | //current_tags.add("this_is_a_test") | |
79 | ||
80 | // Compare tags | |
81 | current_tags.removeAll(previous_tags) | |
82 | ||
83 | // If there are new tags, trigger the builds | |
84 | if (current_tags.size() > 0) { | |
85 | println("Found " + current_tags.size() + "new tags:") | |
86 | for (tag in current_tags) { | |
87 | println(" - ${tag}") | |
88 | } | |
89 | ||
90 | for (jobname in trigger_jobs) { | |
91 | println("Triggering job : ${jobname}") | |
92 | def job = Hudson.instance.getJob(jobname) | |
93 | ||
94 | def params = []; | |
95 | for (paramdef in job.getProperty(ParametersDefinitionProperty.class).getParameterDefinitions()) { | |
96 | params += paramdef.getDefaultParameterValue(); | |
97 | } | |
98 | def paramsAction = new hudson.model.ParametersAction(params) | |
99 | ||
100 | def cause = new Cause.UpstreamCause(build) | |
101 | def causeAction = new CauseAction(cause) | |
102 | ||
103 | Hudson.instance.queue.schedule(job, 0, causeAction, paramsAction) | |
104 | } | |
105 | } else { | |
106 | println("No new tags, nothing to do.") | |
107 | } | |
108 | ||
109 | // EOF |