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', | |
5424b59b | 30 | 'lttng-modules_stable-2.13_build-vanilla', |
8be4ddf2 | 31 | 'lttng-modules_stable-2.12_build-vanilla', |
7f5ffb7a | 32 | 'lttng-modules_stable-2.11_build-vanilla', |
bb368cde | 33 | 'lttng-modules_stable-2.10_build-vanilla', |
9e5c099a | 34 | 'lttng-modules_master_crossbuild-vanilla', |
5424b59b | 35 | 'lttng-modules_stable-2.13_crossbuild-vanilla', |
8be4ddf2 | 36 | 'lttng-modules_stable-2.12_crossbuild-vanilla', |
7f5ffb7a | 37 | 'lttng-modules_stable-2.11_crossbuild-vanilla', |
bb368cde | 38 | 'lttng-modules_stable-2.10_crossbuild-vanilla', |
9e5c099a MJ |
39 | ] |
40 | ||
41 | def previous_tags = [] | |
42 | def current_refs = [] | |
43 | def current_tags = [] as Set | |
44 | ||
45 | // First try to load previous tags from disk | |
46 | try { | |
47 | def input = new ObjectInputStream(new FileInputStream(ondiskpath)) | |
48 | previous_tags = input.readObject() | |
49 | input.close() | |
50 | } catch (all) { | |
51 | println("Failed to load previous tags from disk.") | |
52 | } | |
53 | ||
54 | println("Loaded " + previous_tags.size() + " tags from disk.") | |
55 | //println("Previous tags:") | |
56 | //for (tag in previous_tags) { | |
57 | // println(" - ${tag}") | |
58 | //} | |
59 | ||
60 | // Get current tag refs from git repository | |
61 | current_refs = Git.lsRemoteRepository().setTags(true).setRemote(kgitrepo).call(); | |
62 | ||
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()) | |
68 | } | |
69 | ||
70 | // Write currents tags to disk | |
71 | try { | |
72 | def out = new ObjectOutputStream(new FileOutputStream(ondiskpath)) | |
73 | out.writeObject(current_tags) | |
74 | out.close() | |
75 | } catch (all) { | |
76 | println("Failed to write tags to disk") | |
77 | } | |
78 | ||
79 | // Debug | |
80 | //current_tags.add("this_is_a_test") | |
81 | ||
82 | // Compare tags | |
83 | current_tags.removeAll(previous_tags) | |
84 | ||
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) { | |
89 | println(" - ${tag}") | |
90 | } | |
91 | ||
92 | for (jobname in trigger_jobs) { | |
93 | println("Triggering job : ${jobname}") | |
94 | def job = Hudson.instance.getJob(jobname) | |
95 | ||
96 | def params = []; | |
97 | for (paramdef in job.getProperty(ParametersDefinitionProperty.class).getParameterDefinitions()) { | |
98 | params += paramdef.getDefaultParameterValue(); | |
99 | } | |
100 | def paramsAction = new hudson.model.ParametersAction(params) | |
101 | ||
102 | def cause = new Cause.UpstreamCause(build) | |
103 | def causeAction = new CauseAction(cause) | |
104 | ||
105 | Hudson.instance.queue.schedule(job, 0, causeAction, paramsAction) | |
106 | } | |
107 | } else { | |
108 | println("No new tags, nothing to do.") | |
109 | } | |
110 | ||
111 | // EOF |