Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
JENKINS-50799 Don't end script processing if any section failed
  • Loading branch information
Daniel Heid committed Apr 15, 2018
1 parent 918686f commit f3e6270
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
4 changes: 4 additions & 0 deletions README.md
Expand Up @@ -88,6 +88,10 @@ changes without needing to run to `package` phase.

## Release Notes

### Version 2.7.0

* JENKINS-50799 - Skips script when flagged to run when failing

### Version 2.6.0

Removed access to workspace on master for Groovy script execution, because secure groovy scripts cannot be configured
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -10,7 +10,7 @@
<artifactId>postbuildscript</artifactId>
<packaging>hpi</packaging>
<name>Jenkins PostBuildScript Plugin</name>
<version>2.6.1-SNAPSHOT</version>
<version>2.7.0-SNAPSHOT</version>
<url>http://wiki.jenkins-ci.org/display/JENKINS/PostBuildScript+Plugin</url>
<inceptionYear>2011</inceptionYear>

Expand Down
Expand Up @@ -89,17 +89,11 @@ public boolean process(boolean endOfMatrixBuild) {
}

private boolean processScripts(boolean endOfMatrixBuild) throws PostBuildScriptException {

if (!processScriptFiles(endOfMatrixBuild)) {
return failOrUnstable();
}

if (!processGroovyScripts(endOfMatrixBuild)) {
return failOrUnstable();
}

return processBuildSteps(endOfMatrixBuild) || failOrUnstable();

@SuppressWarnings("NonShortCircuitBooleanExpression")
boolean everyScriptSuccessful = processScriptFiles(endOfMatrixBuild)
& processGroovyScripts(endOfMatrixBuild)
& processBuildSteps(endOfMatrixBuild);
return everyScriptSuccessful || failOrUnstable();
}

private boolean failOrUnstable() {
Expand All @@ -116,6 +110,7 @@ private boolean processScriptFiles(boolean endOfMatrixBuild) throws PostBuildScr
FilePath workspace = build.getWorkspace();
CommandExecutor commandExecutor = new CommandExecutor(logger, listener, workspace, launcher);
GroovyScriptPreparer scriptPreparer = createGroovyScriptPreparer();
boolean everyStepSuccessful = true;
for (ScriptFile scriptFile : config.getScriptFiles()) {
String filePath = scriptFile.getFilePath();
if (Strings.nullToEmpty(filePath).trim().isEmpty()) {
Expand All @@ -133,21 +128,22 @@ private boolean processScriptFiles(boolean endOfMatrixBuild) throws PostBuildScr
if (scriptFile.getScriptType() == ScriptType.GENERIC) {
int returnCode = commandExecutor.executeCommand(command);
if (returnCode != 0) {
return false;
everyStepSuccessful = false;
}
} else {
if (!scriptPreparer.evaluateCommand(scriptFile, command)) {
return false;
everyStepSuccessful = false;
}
}
}
}
return true;
return everyStepSuccessful;
}

private boolean processGroovyScripts(boolean endOfMatrixBuild) {

GroovyScriptPreparer executor = createGroovyScriptPreparer();
boolean everyStepSuccessful = true;
for (Script script : config.getGroovyScripts()) {

String scriptName = Messages.PostBuildScript_GroovyScript(config.groovyScriptIndexOf(script));
Expand All @@ -158,12 +154,12 @@ private boolean processGroovyScripts(boolean endOfMatrixBuild) {
String content = script.getContent();
if (content != null) {
if (!executor.evaluateScript(script)) {
return false;
everyStepSuccessful = false;
}
}

}
return true;
return everyStepSuccessful;
}

private GroovyScriptPreparer createGroovyScriptPreparer() {
Expand All @@ -176,6 +172,7 @@ private GroovyScriptPreparer createGroovyScriptPreparer() {
private boolean processBuildSteps(boolean endOfMatrixBuild) throws PostBuildScriptException {

try {
boolean everyStepSuccessful = true;
for (PostBuildStep postBuildStep : config.getBuildSteps()) {

String scriptName = Messages.PostBuildScript_BuildStep(
Expand All @@ -186,12 +183,11 @@ private boolean processBuildSteps(boolean endOfMatrixBuild) throws PostBuildScri

for (BuildStep buildStep : postBuildStep.getBuildSteps()) {
if (!buildStep.perform(build, launcher, listener)) {
return false;
everyStepSuccessful = false;
}
}

}
return true;
return everyStepSuccessful;
} catch (IOException | InterruptedException ioe) {
throw new PostBuildScriptException(ioe);
}
Expand Down

0 comments on commit f3e6270

Please sign in to comment.