Skip to content

Commit

Permalink
[JENKINS-11219] option to run postbuildscript on Matrix, Axes or Both…
Browse files Browse the repository at this point in the history
… (default)
  • Loading branch information
ndeloof committed Jul 31, 2013
1 parent 754a85c commit be41840
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 9 deletions.
19 changes: 19 additions & 0 deletions src/main/java/org/jenkinsci/plugins/postbuildscript/ExecuteOn.java
@@ -0,0 +1,19 @@
package org.jenkinsci.plugins.postbuildscript;

/**
* @author <a href="mailto:nicolas.deloof@gmail.com">Nicolas De Loof</a>
*/
public enum ExecuteOn {

MATRIX,
AXES,
BOTH;

public boolean matrix() {
return this == MATRIX || this == BOTH;
}

public boolean axes() {
return this == AXES || this == BOTH;
}
}
Expand Up @@ -16,6 +16,10 @@
import java.util.ArrayList;
import java.util.List;

import static org.jenkinsci.plugins.postbuildscript.ExecuteOn.AXES;
import static org.jenkinsci.plugins.postbuildscript.ExecuteOn.BOTH;
import static org.jenkinsci.plugins.postbuildscript.ExecuteOn.MATRIX;

/**
* @author Gregory Boissinot
*/
Expand All @@ -38,30 +42,30 @@ public BuildStepMonitor getRequiredMonitorService() {

private boolean scriptOnlyIfSuccess;
private boolean scriptOnlyIfFailure;
private boolean executeOnMatrixNodes;
private ExecuteOn executeOn;

@DataBoundConstructor
public PostBuildScript(List<GenericScript> genericScriptFile,
List<GroovyScriptFile> groovyScriptFile,
List<GroovyScriptContent> groovyScriptContent,
boolean scriptOnlyIfSuccess,
boolean scriptOnlyIfFailure,
boolean executeOnMatrixNodes,
ExecuteOn executeOn,
List<BuildStep> buildStep) {
this.genericScriptFileList = genericScriptFile;
this.groovyScriptFileList = groovyScriptFile;
this.groovyScriptContentList = groovyScriptContent;
this.buildSteps = buildStep;
this.scriptOnlyIfSuccess = scriptOnlyIfSuccess;
this.scriptOnlyIfFailure = scriptOnlyIfFailure;
this.executeOnMatrixNodes = executeOnMatrixNodes;
this.executeOn = executeOn;
}

public MatrixAggregator createAggregator(MatrixBuild build, Launcher launcher, BuildListener listener) {
return new MatrixAggregator(build, launcher, listener) {
@Override
public boolean endBuild() throws InterruptedException, IOException {
if (!executeOnMatrixNodes)
if (executeOn.matrix())
return _perform(build, launcher, listener);
else
return true;
Expand All @@ -73,7 +77,7 @@ public boolean endBuild() throws InterruptedException, IOException {
public boolean perform(AbstractBuild<?, ?> build, final Launcher launcher, final BuildListener listener) throws InterruptedException, IOException {
Job job = build.getProject();
boolean axe = isMatrixAxe(job);
if ( (axe && executeOnMatrixNodes) // matrix axe, and set to execute on axes' nodes
if ( (axe && executeOn.axes()) // matrix axe, and set to execute on axes' nodes
|| (!axe)) { // neither matrix head nor axe
return _perform(build, launcher, listener);
}
Expand Down Expand Up @@ -277,8 +281,8 @@ public boolean isScriptOnlyIfFailure() {
}

@SuppressWarnings("unused")
public boolean isExecuteOnMatrixNodes() {
return executeOnMatrixNodes;
public ExecuteOn getExecuteOn() {
return executeOn;
}

@Extension(ordinal = 99)
Expand Down Expand Up @@ -356,6 +360,8 @@ public Object readResolve() {
}
}

if (executeOn == null) executeOn = BOTH;

return this;
}

Expand Down
Expand Up @@ -99,8 +99,13 @@
</f:entry>

<j:if test="${descriptor.isMatrixProject(it)}">
<f:entry title="${%Execute script on each axe}" field="executeOnMatrixNodes">
<f:checkbox/>
<f:entry title="${%Execute script on}">
<select name="executeOn">
<j:invokeStatic var="values" className="org.jenkinsci.plugins.postbuildscript.ExecuteOn" method="values"/>
<j:forEach items="${values}" var="value">
<f:option selected="${instance.executeOn == value}">${value}</f:option>
</j:forEach>
</select>
</f:entry>
</j:if>

Expand Down

0 comments on commit be41840

Please sign in to comment.