Skip to content

Commit

Permalink
Build really fails when failOnError set to true (#929)
Browse files Browse the repository at this point in the history
  • Loading branch information
ymougenel authored Oct 22, 2023
1 parent 7562839 commit 1ee9db1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import hudson.Extension;
import hudson.Util;
import hudson.model.Item;
import hudson.model.Result;
import hudson.model.Run;
import hudson.model.TaskListener;
import hudson.util.ListBoxModel;
Expand Down Expand Up @@ -361,6 +362,10 @@ protected SlackResponse run() throws Exception {
} else {
listener.error(Messages
.notificationFailedWithException(new IllegalArgumentException("No message, attachments or blocks provided")));
if (step.isFailOnError()) {

Check warning on line 365 in src/main/java/jenkins/plugins/slack/workflow/SlackSendStep.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 365 is only partially covered, one branch is missing
run.setResult(Result.FAILURE);
throw new AbortException("No message, attachments or blocks provided");
}
return null;
}
SlackResponse response = null;
Expand All @@ -373,13 +378,15 @@ protected SlackResponse run() throws Exception {
} catch (org.json.JSONException ex) {
listener.error(Messages.failedToParseSlackResponse(responseString));
if (step.failOnError) {
run.setResult(Result.FAILURE);

Check warning on line 381 in src/main/java/jenkins/plugins/slack/workflow/SlackSendStep.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 381 is not covered by tests
throw ex;
}
}
} else {
return new SlackResponse(slackService);
}
} else if (step.failOnError) {
run.setResult(Result.FAILURE);
if (responseString != null) {
throw new AbortException(Messages.notificationFailedWithException(responseString));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,12 @@ public void test_fail_on_error() throws Exception {
//everything should come from step configuration
jenkinsRule.assertLogContains(Messages.notificationFailed(), run);
}

@Test
public void test_fail_on_missing_message() throws Exception {
WorkflowJob job = jenkinsRule.jenkins.createProject(WorkflowJob.class, "workflow");
//with a null message
job.setDefinition(new CpsFlowDefinition("slackSend(message: null, baseUrl: 'baseUrl', teamDomain: 'teamDomain', token: 'token', tokenCredentialId: 'tokenCredentialId', channel: '#channel', color: 'good', failOnError: true);", true));
jenkinsRule.assertBuildStatus(Result.FAILURE, job.scheduleBuild2(0).get());
}
}

0 comments on commit 1ee9db1

Please sign in to comment.