-
Notifications
You must be signed in to change notification settings - Fork 557
/
jira-publisher.groovy
58 lines (56 loc) · 1.68 KB
/
jira-publisher.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*** BEGIN META {
"name" : "Jira issue update publisher",
"comment" : 'Activate the <a href="https://wiki.jenkins-ci.org/display/JENKINS/JIRA+Plugin">Jira plugin</a> publisher',
"parameters" : ['dryRun','jobs','jobsPattern'],
"core": "1.424",
"authors" : [
{ name : "Julien Carsique" }
]
} END META**/
import hudson.model.*
if (dryRun == "true") {
println("Dry run")
}
def jobsList = []
if (!jobs.isEmpty()) {
println("Working with jobs list: $jobs")
for (jobName in jobs.split()) {
jobItem = Hudson.getInstance().getItem(jobName)
if (jobItem == null) {
println("WARN $jobName not found!")
continue
}
jobsList.add(jobItem)
}
}
if (!jobsPattern.isEmpty()) {
println("Working with jobs pattern: $jobsPattern")
for (jobItem in Hudson.getInstance().getItems()) {
for (jobPattern in jobsPattern.split()) {
if (jobItem.getName() =~ jobPattern) {
jobsList.add(jobItem)
break
}
}
}
}
if (jobs.isEmpty() && jobsPattern.isEmpty()) {
jobsList = Hudson.getInstance().getItems()
}
for(item in jobsList) {
println("\n[$item.name]")
hasJira = false;
for(p in item.getPublishersList()) {
if(p instanceof hudson.plugins.jira.JiraIssueUpdater) {
println("Jira publisher already active on $item.name")
hasJira = true
}
}
if(!hasJira) {
println("Adding Jira publisher to $item.name")
if (dryRun != "true") {
item.getPublishersList().add(new hudson.plugins.jira.JiraIssueUpdater())
item.save()
}
}
}