-
-
Notifications
You must be signed in to change notification settings - Fork 295
Expand file tree
/
Copy pathJiraIssueUpdateBuilder.java
More file actions
161 lines (140 loc) · 5.18 KB
/
JiraIssueUpdateBuilder.java
File metadata and controls
161 lines (140 loc) · 5.18 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/*
* Copyright 2012 MeetMe, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package hudson.plugins.jira;
import com.atlassian.jira.rest.client.api.RestClientException;
import hudson.EnvVars;
import hudson.Extension;
import hudson.Util;
import hudson.model.*;
import hudson.tasks.BuildStepDescriptor;
import hudson.tasks.Builder;
import hudson.util.FormValidation;
import java.io.IOException;
import jenkins.tasks.SimpleBuildStep;
import org.apache.commons.lang.StringUtils;
import org.jenkinsci.Symbol;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.QueryParameter;
/**
* Build step that will mass-update all issues matching a JQL query, using the specified workflow
* action name (e.g., "Resolve Issue", "Close Issue").
*
* @author Joe Hansche jhansche@myyearbook.com
*/
public class JiraIssueUpdateBuilder extends Builder implements SimpleBuildStep {
private final String jqlSearch;
private final String workflowActionName;
private final String comment;
@DataBoundConstructor
public JiraIssueUpdateBuilder(String jqlSearch, String workflowActionName, String comment) {
this.jqlSearch = Util.fixEmptyAndTrim(jqlSearch);
this.workflowActionName = Util.fixEmptyAndTrim(workflowActionName);
this.comment = Util.fixEmptyAndTrim(comment);
}
/**
* @return the jql
*/
public String getJqlSearch() {
return jqlSearch;
}
/**
* @return the workflowActionName
*/
public String getWorkflowActionName() {
return workflowActionName;
}
/**
* @return the comment
*/
public String getComment() {
return comment;
}
JiraSite getSiteForJob(Job<?, ?> job) {
return JiraSite.get(job);
}
/**
* Performs the actual update based on job configuration.
*/
@Override
public void perform(Run<?, ?> run, EnvVars env, TaskListener listener) throws InterruptedException, IOException {
String realComment = Util.fixEmptyAndTrim(env.expand(comment));
String realJql = Util.fixEmptyAndTrim(env.expand(jqlSearch));
String realWorkflowActionName = Util.fixEmptyAndTrim(env.expand(workflowActionName));
JiraSite site = getSiteForJob(run.getParent());
if (site == null) {
listener.getLogger().println(Messages.NoJiraSite());
run.setResult(Result.FAILURE);
return;
}
if (StringUtils.isNotEmpty(realWorkflowActionName)) {
listener.getLogger().println(Messages.JiraIssueUpdateBuilder_UpdatingWithAction(realWorkflowActionName));
}
listener.getLogger().println("[Jira] JQL: " + realJql);
try {
if (!site.progressMatchingIssues(realJql, realWorkflowActionName, realComment, listener.getLogger())) {
listener.getLogger().println(Messages.JiraIssueUpdateBuilder_SomeIssuesFailed());
run.setResult(Result.UNSTABLE);
}
} catch (RestClientException e) {
listener.getLogger().println(e.getMessage());
run.setResult(Result.FAILURE);
}
}
@Override
public boolean requiresWorkspace() {
return false;
}
@Override
public DescriptorImpl getDescriptor() {
return (DescriptorImpl) super.getDescriptor();
}
/**
* Descriptor for {@link JiraIssueUpdateBuilder}.
*/
@Extension
@Symbol("jiraExecuteWorkflow")
public static final class DescriptorImpl extends BuildStepDescriptor<Builder> {
/**
* Performs on-the-fly validation of the form field 'Jql'.
*
* @param value This parameter receives the value that the user has typed.
* @return Indicates the outcome of the validation. This is sent to the browser.
*/
public FormValidation doCheckJqlSearch(@QueryParameter String value) {
if (value.length() == 0) {
return FormValidation.error(Messages.JiraIssueUpdateBuilder_NoJqlSearch());
}
return FormValidation.ok();
}
public FormValidation doCheckWorkflowActionName(@QueryParameter String value) {
if (Util.fixNull(value).trim().length() == 0) {
return FormValidation.warning(Messages.JiraIssueUpdateBuilder_NoWorkflowAction());
}
return FormValidation.ok();
}
@Override
public boolean isApplicable(Class<? extends AbstractProject> klass) {
return true;
}
/**
* This human readable name is used in the configuration screen.
*/
@Override
public String getDisplayName() {
return Messages.JiraIssueUpdateBuilder_DisplayName();
}
}
}