Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FIXED JENKINS-13652] Add ability to update issues by workflow actions.
A new build step that takes a JQL query, and for each matching issue, performs a configurable workflow step (such as "Resolve Issue"). Optionally adds a comment to each issue as it is updated.
- Loading branch information
Joe Hansche
committed
May 30, 2012
1 parent
571fb36
commit 90c466a
Showing
9 changed files
with
317 additions
and
1 deletion.
There are no files selected for viewing
137 changes: 137 additions & 0 deletions
137
src/main/java/hudson/plugins/jira/JiraIssueUpdateBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
package hudson.plugins.jira; | ||
|
||
import hudson.Extension; | ||
import hudson.Launcher; | ||
import hudson.Util; | ||
import hudson.model.BuildListener; | ||
import hudson.model.AbstractBuild; | ||
import hudson.model.AbstractProject; | ||
import hudson.model.Result; | ||
import hudson.tasks.BuildStepDescriptor; | ||
import hudson.tasks.Builder; | ||
import hudson.util.FormValidation; | ||
|
||
import java.io.IOException; | ||
|
||
import javax.servlet.ServletException; | ||
import javax.xml.rpc.ServiceException; | ||
|
||
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 { | ||
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; | ||
} | ||
|
||
/** | ||
* Performs the actual update based on job configuration. | ||
*/ | ||
@Override | ||
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException { | ||
String realComment = Util.fixEmptyAndTrim(build.getEnvironment(listener).expand(comment)); | ||
String realJql = Util.fixEmptyAndTrim(build.getEnvironment(listener).expand(jqlSearch)); | ||
|
||
JiraSite site = JiraSite.get(build.getProject()); | ||
|
||
if (site == null) { | ||
listener.getLogger().println(Messages.Updater_NoJiraSite()); | ||
build.setResult(Result.FAILURE); | ||
return true; | ||
} | ||
|
||
listener.getLogger().println(Messages.JiraIssueUpdateBuilder_UpdatingWithAction(workflowActionName)); | ||
listener.getLogger().println("[JIRA] JQL: " + realJql); | ||
|
||
try { | ||
if (!site.progressMatchingIssues(realJql, workflowActionName, realComment, listener.getLogger())) { | ||
listener.getLogger().println(Messages.JiraIssueUpdateBuilder_SomeIssuesFailed()); | ||
build.setResult(Result.UNSTABLE); | ||
} | ||
} catch (ServiceException e) { | ||
listener.getLogger().println(Messages.JiraIssueUpdateBuilder_Failed()); | ||
e.printStackTrace(listener.getLogger()); | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
@Override | ||
public DescriptorImpl getDescriptor() { | ||
return (DescriptorImpl) super.getDescriptor(); | ||
} | ||
|
||
/** | ||
* Descriptor for {@link JiraIssueUpdateBuilder}. | ||
*/ | ||
@Extension | ||
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) throws IOException, ServletException { | ||
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.error(Messages.JiraIssueUpdateBuilder_NoWorkflowAction()); | ||
} | ||
|
||
return FormValidation.ok(); | ||
} | ||
|
||
public boolean isApplicable(Class<? extends AbstractProject> klass) { | ||
return true; | ||
} | ||
|
||
/** | ||
* This human readable name is used in the configuration screen. | ||
*/ | ||
public String getDisplayName() { | ||
return Messages.JiraIssueUpdateBuilder_DisplayName(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
src/main/resources/hudson/plugins/jira/JiraIssueUpdateBuilder/config.jelly
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<j:jelly xmlns:j="jelly:core" xmlns:f="/lib/form"> | ||
<f:entry title="${%JQL Query}" field="jqlSearch"> | ||
<f:textbox/> | ||
</f:entry> | ||
<f:entry title="${%Workflow Action}" field="workflowActionName"> | ||
<f:textbox/> | ||
</f:entry> | ||
<f:entry title="${%Comment}" field="comment"> | ||
<f:textarea/> | ||
</f:entry> | ||
</j:jelly> |
5 changes: 5 additions & 0 deletions
5
src/main/resources/hudson/plugins/jira/JiraIssueUpdateBuilder/help-comment.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<div> | ||
An optional comment to be added to the issue after updating the workflow. If left empty, no comment will be added. | ||
<p /> | ||
This can contain <strong>$PARAM</strong> values which will be replaced by the build parameters. | ||
</div> |
12 changes: 12 additions & 0 deletions
12
src/main/resources/hudson/plugins/jira/JiraIssueUpdateBuilder/help-jqlSearch.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<div> | ||
Issues which match this JQL Query will be progressed using the specified workflow action. | ||
<p /> | ||
This can contain <strong>$PARAM</strong> values which will be replaced by the build parameters. | ||
|
||
<p> | ||
Example: | ||
<blockquote><pre>project = JENKINS and fixVersion = "$RELEASE_VERSION" and status not in (Resolved, Closed)</pre></blockquote> | ||
or (e.g., combined with a JIRA Issue Parameter, selecting one issue from a JQL result set): | ||
<blockquote><pre>issue = $ISSUE_ID</pre></blockquote> | ||
</p> | ||
</div> |
5 changes: 5 additions & 0 deletions
5
src/main/resources/hudson/plugins/jira/JiraIssueUpdateBuilder/help-workflowActionName.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<div> | ||
The workflow action to be performed on the selected JIRA issues. | ||
<p /> | ||
Be mindful of the issues being selected by the JQL query, because not all actions are valid for all issue statuses. | ||
</div> |
8 changes: 8 additions & 0 deletions
8
src/main/resources/hudson/plugins/jira/JiraIssueUpdateBuilder/help.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<div> | ||
Performs a JIRA workflow action for every issue that matches the JQL query. | ||
A common use might be to consider a ticket "confirmed" in the last build step | ||
of a job, or to mark an issue as "merged" if the job is used to merge changes | ||
from one SCM repository to another. | ||
<p /> | ||
Optionally, include a comment that will be attached to those tickets that are modified as a result of this build step. | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters