Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Workflow step for setting unsuccessful message
Add a workflow step that allows setting the unsuccessful message from a workflow build. config.jelly is currently missing. Dependency to the workflow plugin is optional. Implements a limited part of [JENKINS-26103].
- Loading branch information
1 parent
963b25f
commit 427d422
Showing
7 changed files
with
249 additions
and
6 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
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
121 changes: 121 additions & 0 deletions
121
src/main/java/com/sonyericsson/hudson/plugins/gerrit/trigger/workflow/GerritReviewStep.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,121 @@ | ||
/* | ||
* The MIT License | ||
* | ||
* Copyright (c) 2016 Teemu Murtola. | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
*/ | ||
package com.sonyericsson.hudson.plugins.gerrit.trigger.workflow; | ||
|
||
import com.sonyericsson.hudson.plugins.gerrit.trigger.gerritnotifier.ToGerritRunListener; | ||
import hudson.Extension; | ||
import hudson.Util; | ||
import hudson.model.Run; | ||
import javax.annotation.CheckForNull; | ||
import javax.inject.Inject; | ||
import org.jenkinsci.plugins.workflow.steps.AbstractStepDescriptorImpl; | ||
import org.jenkinsci.plugins.workflow.steps.AbstractStepImpl; | ||
import org.jenkinsci.plugins.workflow.steps.AbstractSynchronousStepExecution; | ||
import org.jenkinsci.plugins.workflow.steps.StepContextParameter; | ||
import org.kohsuke.stapler.DataBoundConstructor; | ||
import org.kohsuke.stapler.DataBoundSetter; | ||
|
||
/** | ||
* Allows altering the Gerrit review posted at the end of build during the build. | ||
* @author Teemu Murtola <teemu.murtola@gmail.com> | ||
*/ | ||
public class GerritReviewStep extends AbstractStepImpl { | ||
|
||
private String unsuccessfulMessage; | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* There are no mandatory parameters to the step. | ||
*/ | ||
@DataBoundConstructor | ||
public GerritReviewStep() { | ||
} | ||
|
||
/** | ||
* Gets the unsuccessful message for a step. | ||
* @return the message. | ||
*/ | ||
@CheckForNull | ||
public String getUnsuccessfulMessage() { | ||
return unsuccessfulMessage; | ||
} | ||
|
||
/** | ||
* Sets additional information to post for a failed build. | ||
* @param unsuccessfulMessage Additional information to post for a failed build. | ||
*/ | ||
@DataBoundSetter | ||
public void setUnsuccessfulMessage(String unsuccessfulMessage) { | ||
this.unsuccessfulMessage = Util.fixEmptyAndTrim(unsuccessfulMessage); | ||
} | ||
|
||
/** | ||
* Executes the GerritReviewStep. | ||
*/ | ||
public static class Execution extends AbstractSynchronousStepExecution<Void> { | ||
|
||
@StepContextParameter | ||
private transient Run build; | ||
|
||
@Inject | ||
private transient GerritReviewStep step; | ||
|
||
@Override | ||
protected Void run() throws Exception { | ||
ToGerritRunListener listener = ToGerritRunListener.getInstance(); | ||
String unsuccessfulMessage = step.getUnsuccessfulMessage(); | ||
if (unsuccessfulMessage != null) { | ||
listener.setBuildFailureMessage(build, unsuccessfulMessage); | ||
} | ||
return null; | ||
} | ||
|
||
private static final long serialVersionUID = 1L; | ||
} | ||
|
||
/** | ||
* Adds the step as a workflow extension. | ||
*/ | ||
@Extension(optional = true) | ||
public static class DescriptorImpl extends AbstractStepDescriptorImpl { | ||
|
||
/** | ||
* Constructor. | ||
*/ | ||
public DescriptorImpl() { | ||
super(Execution.class); | ||
} | ||
|
||
@Override | ||
public String getFunctionName() { | ||
return "gerritReview"; | ||
} | ||
|
||
@Override | ||
public String getDisplayName() { | ||
return "Set Gerrit review"; | ||
} | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
...ces/com/sonyericsson/hudson/plugins/gerrit/trigger/workflow/GerritReviewStep/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,31 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
The MIT License | ||
Copyright (c) 2016 Teemu Murtola. | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. | ||
--> | ||
|
||
<?jelly escape-by-default='true'?> | ||
<j:jelly xmlns:j="jelly:core" xmlns:f="/lib/form"> | ||
<f:entry field="unsuccessfulMessage" title="${%Unsuccessful message}"> | ||
<f:textarea /> | ||
</f:entry> | ||
</j:jelly> |
3 changes: 3 additions & 0 deletions
3
...son/hudson/plugins/gerrit/trigger/workflow/GerritReviewStep/help-unsuccessfulMessage.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> | ||
Additional details to post back to Gerrit if the build is not successful. | ||
</div> |
12 changes: 12 additions & 0 deletions
12
...ources/com/sonyericsson/hudson/plugins/gerrit/trigger/workflow/GerritReviewStep/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,12 @@ | ||
<div> | ||
<p> | ||
Allows influencing how the build results are reported back to Gerrit. | ||
All input values are optional. If the step occurs multiple times in | ||
a workflow, the last value set for each parameter is used. | ||
</p> | ||
<p> | ||
If the build is not triggered by Gerrit Trigger, or if the trigger is | ||
configured to not report back to Gerrit when the build finishes, | ||
this step does nothing. | ||
</p> | ||
</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