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