Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JENKINS-68729 Abort the build on error #114

Merged
merged 1 commit into from
Jun 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

55 changes: 47 additions & 8 deletions src/main/java/io/jenkins/plugins/dotnet/commands/Command.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ public static DotNetSDK.DescriptorImpl getSdkDescriptor() throws AbortException
* @throws IOException When an I/O error occurs.
*/
@Override
public void perform(@NonNull Run<?, ?> run, @NonNull FilePath workspace, @NonNull EnvVars env, @NonNull Launcher launcher, @NonNull TaskListener listener) throws InterruptedException, IOException {
public void perform(@NonNull Run<?, ?> run, @NonNull FilePath workspace, @NonNull EnvVars env, @NonNull Launcher launcher,
@NonNull TaskListener listener) throws InterruptedException, IOException {
final Charset cs = this.charset == null ? run.getCharset() : Charset.forName(this.charset);
final DotNetSDK sdkInstance;
if (this.sdk == null)
Expand Down Expand Up @@ -120,18 +121,32 @@ public void perform(@NonNull Run<?, ?> run, @NonNull FilePath workspace, @NonNul
final ArgumentListBuilder cmdLine = new ArgumentListBuilder(executable, "build-server", "shutdown");
launcher.launch().cmds(cmdLine).envs(env).stdout(scanner).pwd(workspace).join();
}
// TODO: Maybe also add configuration to set the build as either failed or unstable based on return code
if (scanner.getErrors() > 0) {
run.setResult(this.unstableIfErrors ? Result.UNSTABLE : Result.FAILURE);
}
else {
if (this.unstableIfWarnings && scanner.getWarnings() > 0) {
final int errors = scanner.getErrors();
if (errors > 0) {
if (this.unstableIfErrors) {
run.setResult(Result.UNSTABLE);
}
if (rc != 0) {
else if (this.continueOnError) {
run.setResult(Result.FAILURE);
}
else {
throw new AbortException(Messages.Command_ExecutionCompletedWithErrors(errors));
}
}
else if (rc != 0) {
if (this.continueOnError) {
run.setResult(Result.FAILURE);
}
else {
throw new AbortException(Messages.Command_ExecutionCompletedWithNonZeroReturnCode(rc));
}
}
else if (this.unstableIfWarnings && scanner.getWarnings() > 0) {
run.setResult(Result.UNSTABLE);
}
}
catch (AbortException ae) {
throw ae;
}
catch (Throwable t) {
Functions.printStackTrace(t, listener.fatalError(Messages.Command_ExecutionFailed()));
Expand Down Expand Up @@ -171,6 +186,30 @@ public void setCharset(@CheckForNull String charset) {
this.charset = Util.fixEmptyAndTrim(charset);
}

private boolean continueOnError = false;

/**
* Determines whether the build should continue when there is an error.
*
* @return {@code false} if the build should be aborted when there is an error; {@code true} to set build status to failed or
* unstable, based on configuration, but allow the next build step to execute.
*/
@SuppressWarnings("unused")
public boolean isContinueOnError() {
return this.continueOnError;
}

/**
* Determines whether the build should continue when there is an error.
*
* @param continueOnError {@code false} if the build should be aborted when there is an error; {@code true} if the build status
* should be set to failed or unstable, based on configuration, allowing the next build step to execute.
*/
@DataBoundSetter
public void setContinueOnError(boolean continueOnError) {
this.continueOnError = continueOnError;
}

/** The name of the SDK to use. */
@CheckForNull
protected String sdk;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<div>
If this is checked, errors encountered will cause the build status to be set to <code>FAILURE</code> (or <code>UNSTABLE</code>, if
configured that way), but the build will be allowed to continue. Otherwise, any such errors will cause the build to be terminated
immediately.
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@
<f:textbox/>
</f:entry>

<f:entry title="${%Continue On Error}" field="continueOnError">
<f:checkbox/>
</f:entry>

</j:jelly>
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
Continue\ On\ Error=Continuer en cas d'erreurs
Work\ Directory=Dossier de travail
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
Continue\ On\ Error=Doorgaan bij fouten
Work\ Directory=Werkfolder
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
Command.DefaultSDK=(Default)
Command.ExecutionFailed=Command execution failed
Command.ExecutionCompletedWithErrors=Command execution completed with {0} error(s).
Command.ExecutionCompletedWithNonZeroReturnCode=Command execution completed with return code {0}.
Command.ExecutionFailed=Command execution failed.
Command.MoreOptions=More Options
Command.SameCharsetAsBuild=<Same As Rest of Build>
Command.UnsupportedCharset=Unsupported character set
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
Command.DefaultSDK=(D�faut)
Command.ExecutionFailed=L'ex�cution de l'ordre a �chou�
Command.ExecutionCompletedWithErrors=Ex�cution de l'ordre termin�e avec {0} erreur(s).
Command.ExecutionCompletedWithNonZeroReturnCode=Ex�cution de l'ordre termin�e avec code de retour {0}.
Command.ExecutionFailed=L'ex�cution de l'ordre a �chou�.
Command.MoreOptions=Options additionnelles
Command.SameCharsetAsBuild=Identique au reste du build
Command.UnsupportedCharset=Jeu de caract�res non support�
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
Command.DefaultSDK=(Standaard)
Command.ExecutionFailed=Uitvoeren van commando mislukt
Command.ExecutionCompletedWithErrors=Uitvoeren van commando be�indigd met {0} fout(en).
Command.ExecutionCompletedWithNonZeroReturnCode=Uitvoeren van commando be�indigd met code {0}.
Command.ExecutionFailed=Uitvoeren van commando mislukt.
Command.MoreOptions=Meer opties
Command.SameCharsetAsBuild=<Hetzelfde als de rest van de build>
Command.UnsupportedCharset=Deze tekenset wordt niet ondersteund
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<div>
If this is set and the build completes with errors, the build will be marked as unstable instead of failed.
If this is set and the build completes with errors, the build will be marked as unstable instead of failed, and execution will
continue to the next step.
</div>
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:f="/lib/form" xmlns:s="jelly:stapler">

<s:include page="options.jelly" class="io.jenkins.plugins.dotnet.commands.Command"/>

<f:entry title="${%Configuration}" field="configuration">
<f:combobox/>
</f:entry>

<s:include page="options.jelly" class="io.jenkins.plugins.dotnet.commands.Command"/>

<f:entry title="${%Errors Result in Unstable Build}" field="unstableIfErrors">
<f:checkbox/>
</f:entry>
Expand Down