Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ability to abort the jira version release in case of build failure
- Loading branch information
1 parent
efabd47
commit dd98655
Showing
7 changed files
with
162 additions
and
39 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -7,3 +7,4 @@ bin | |
*.iml | ||
.idea/ | ||
work | ||
atlassian-ide-plugin.xml |
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
92 changes: 92 additions & 0 deletions
92
src/main/java/hudson/plugins/jira/JiraReleaseVersionUpdaterBuilder.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,92 @@ | ||
package hudson.plugins.jira; | ||
|
||
import hudson.Extension; | ||
import hudson.Launcher; | ||
import hudson.model.AbstractBuild; | ||
import hudson.model.AbstractProject; | ||
import hudson.model.BuildListener; | ||
import hudson.model.Descriptor; | ||
import hudson.tasks.BuildStepDescriptor; | ||
import hudson.tasks.Builder; | ||
import net.sf.json.JSONObject; | ||
import org.kohsuke.stapler.DataBoundConstructor; | ||
import org.kohsuke.stapler.StaplerRequest; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
* Created by Reda on 18/12/2014. | ||
*/ | ||
public class JiraReleaseVersionUpdaterBuilder extends Builder { | ||
|
||
private String jiraProjectKey; | ||
private String jiraRelease; | ||
|
||
@Extension | ||
public static final DescriptorImpl DESCRIPTOR = new DescriptorImpl(); | ||
|
||
@DataBoundConstructor | ||
public JiraReleaseVersionUpdaterBuilder(String jiraProjectKey, String jiraRelease) { | ||
this.jiraRelease = jiraRelease; | ||
this.jiraProjectKey = jiraProjectKey; | ||
} | ||
|
||
public String getJiraRelease() { | ||
return jiraRelease; | ||
} | ||
|
||
public void setJiraRelease(String jiraRelease) { | ||
this.jiraRelease = jiraRelease; | ||
} | ||
|
||
public String getJiraProjectKey() { | ||
return jiraProjectKey; | ||
} | ||
|
||
public void setJiraProjectKey(String jiraProjectKey) { | ||
this.jiraProjectKey = jiraProjectKey; | ||
} | ||
|
||
@Override | ||
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException { | ||
return Releaser.perform(getSiteForProject(build.getProject()), jiraProjectKey, jiraRelease, build, listener); | ||
} | ||
|
||
JiraSite getSiteForProject(AbstractProject<?, ?> project) { | ||
return JiraSite.get(project); | ||
} | ||
|
||
@Override | ||
public Descriptor<Builder> getDescriptor() { | ||
return DESCRIPTOR; | ||
} | ||
|
||
public static final class DescriptorImpl extends BuildStepDescriptor<Builder> { | ||
|
||
private DescriptorImpl() { | ||
super(JiraReleaseVersionUpdaterBuilder.class); | ||
} | ||
|
||
@Override | ||
public boolean isApplicable(Class<? extends AbstractProject> jobType) { | ||
return true; | ||
} | ||
|
||
@Override | ||
public String getDisplayName() { | ||
// Placed in the build settings section | ||
return Messages.JiraReleaseVersionBuilder_DisplayName(); | ||
} | ||
|
||
@Override | ||
public String getHelpFile() { | ||
return "/plugin/jira/help.html"; | ||
} | ||
|
||
@Override | ||
public JiraReleaseVersionUpdaterBuilder newInstance(StaplerRequest req, JSONObject formData) | ||
throws FormException { | ||
return req.bindJSON(JiraReleaseVersionUpdaterBuilder.class, formData); | ||
} | ||
} | ||
} |
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,51 @@ | ||
package hudson.plugins.jira; | ||
|
||
import hudson.model.AbstractBuild; | ||
import hudson.model.BuildListener; | ||
import hudson.model.Result; | ||
|
||
import java.util.List; | ||
|
||
import static ch.lambdaj.Lambda.filter; | ||
import static hudson.plugins.jira.JiraVersionMatcher.hasName; | ||
import static org.hamcrest.Matchers.equalTo; | ||
|
||
/** | ||
* Created by Reda on 18/12/2014. | ||
*/ | ||
public class Releaser { | ||
|
||
private static final String VERSION_ALREADY_RELEASED = | ||
"The version %s is already released in project %s, so nothing to do."; | ||
|
||
static boolean perform(JiraSite site, String jiraProjectKey, String jiraRelease, AbstractBuild<?, ?> build, BuildListener listener) { | ||
String realRelease = "NOT_SET"; | ||
|
||
try { | ||
realRelease = build.getEnvironment(listener).expand(jiraRelease); | ||
|
||
if (realRelease == null || realRelease.isEmpty()) { | ||
throw new IllegalArgumentException("Release is Empty"); | ||
} | ||
|
||
List<JiraVersion> sameNamedVersions = filter( | ||
hasName(equalTo(realRelease)), | ||
site.getVersions(jiraProjectKey)); | ||
|
||
if (sameNamedVersions.size() == 1 && sameNamedVersions.get(0).isReleased()) { | ||
listener.getLogger().println( | ||
String.format(VERSION_ALREADY_RELEASED, realRelease, jiraProjectKey)); | ||
} else { | ||
site.releaseVersion(jiraProjectKey, realRelease); | ||
} | ||
} catch (Exception e) { | ||
e.printStackTrace(listener.fatalError( | ||
"Unable to release jira version %s/%s: %s", realRelease, | ||
jiraProjectKey, e)); | ||
listener.finished(Result.FAILURE); | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
} |
8 changes: 8 additions & 0 deletions
8
src/main/resources/hudson/plugins/jira/JiraReleaseVersionUpdaterBuilder/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,8 @@ | ||
<j:jelly xmlns:j="jelly:core" xmlns:f="/lib/form"> | ||
<f:entry title="${%Jira Release}" field="jiraRelease"> | ||
<f:textbox/> | ||
</f:entry> | ||
<f:entry title="${%Jira Project Key}" field="jiraProjectKey"> | ||
<f:textbox/> | ||
</f:entry> | ||
</j:jelly> |
4 changes: 4 additions & 0 deletions
4
...n/resources/hudson/plugins/jira/JiraReleaseVersionUpdaterBuilder/help-jiraProjectKey.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,4 @@ | ||
<div> | ||
<p>Specify the project key. A project key is the all capitals part before the issue number in JIRA.</p> | ||
<p>(<strong>EXAMPLE</strong>-100)</p> | ||
</div> |
3 changes: 3 additions & 0 deletions
3
...main/resources/hudson/plugins/jira/JiraReleaseVersionUpdaterBuilder/help-jiraRelease.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,3 @@ | ||
<div> | ||
Specify the name of the parameter which will contain the release version. This can reference a build parameter. | ||
</div> |