Skip to content

Commit 015261f

Browse files
rantoniukHardik RathodHardikrathod01Copilot
authored
log appropriate error messages to build console (#759)
closes #711 #702 * Throw JiraException from getVersions method call * Apply spotless changes * Remove unused method * Replace JiraException class with RestClientException class * Handle errors of addComment and getIssue methods in their root calling methods * Handle errors of getProjectKeys method * Handle errors of all the other remaining methods * Remove unnecessary multi catch * Throw JiraException from getVersions method call * Apply spotless changes * Remove unused method * Replace JiraException class with RestClientException class * Handle errors of addComment and getIssue methods in their root calling methods * Handle errors of getProjectKeys method * Handle errors of all the other remaining methods * Remove unnecessary multi catch * Fix spotless issue * Update for adding test cases * - Update for Replacing "Jira Error" with Jira - Catch specific exceptions rather than catching general Exception * - Fix never thrown exception catch error * - Fix test cases * - Replace TimeoutException tests with RestclientException tests * - Remove not thrown exception from doc * - Fix spotless issues * - Handle IOException and RestClientException in a single catch * Apply CoPilot suggestions from code review Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Hardik Rathod <hardik.rathod@fruitcore.de> Co-authored-by: Hardikrathod01 <42797234+Hardikrathod01@users.noreply.github.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent d200565 commit 015261f

29 files changed

+472
-146
lines changed

src/main/java/hudson/plugins/jira/JiraCreateIssueNotifier.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import static hudson.plugins.jira.JiraRestService.BUG_ISSUE_TYPE_ID;
44

5+
import com.atlassian.jira.rest.client.api.RestClientException;
56
import com.atlassian.jira.rest.client.api.StatusCategory;
67
import com.atlassian.jira.rest.client.api.domain.Issue;
78
import com.atlassian.jira.rest.client.api.domain.IssueType;
@@ -164,12 +165,16 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListen
164165
}
165166

166167
if (currentBuildResult != Result.ABORTED && previousBuild != null) {
167-
if (currentBuildResult == Result.FAILURE) {
168-
currentBuildResultFailure(build, listener, previousBuildResult, filename, vars);
169-
}
168+
try {
169+
if (currentBuildResult == Result.FAILURE) {
170+
currentBuildResultFailure(build, listener, previousBuildResult, filename, vars);
171+
}
170172

171-
if (currentBuildResult == Result.SUCCESS) {
172-
currentBuildResultSuccess(build, listener, previousBuildResult, filename, vars);
173+
if (currentBuildResult == Result.SUCCESS) {
174+
currentBuildResultSuccess(build, listener, previousBuildResult, filename, vars);
175+
}
176+
} catch (RestClientException e) {
177+
listener.getLogger().println(e.getMessage());
173178
}
174179
}
175180
return true;
@@ -342,7 +347,7 @@ private void currentBuildResultFailure(
342347
Result previousBuildResult,
343348
String filename,
344349
EnvVars vars)
345-
throws InterruptedException, IOException {
350+
throws InterruptedException, IOException, RestClientException {
346351

347352
if (previousBuildResult == Result.FAILURE) {
348353
String comment = String.format("Build is still failing.%nFailed run: %s", getBuildDetailsString(vars));

src/main/java/hudson/plugins/jira/JiraEnvironmentVariableBuilder.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package hudson.plugins.jira;
22

3+
import com.atlassian.jira.rest.client.api.RestClientException;
34
import hudson.Extension;
45
import hudson.Launcher;
56
import hudson.model.AbstractBuild;
@@ -50,7 +51,13 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListen
5051
return false;
5152
}
5253

53-
Set<String> ids = getIssueSelector().findIssueIds(build, site, listener);
54+
Set<String> ids;
55+
try {
56+
ids = getIssueSelector().findIssueIds(build, site, listener);
57+
} catch (RestClientException e) {
58+
listener.getLogger().println(e.getMessage());
59+
return false;
60+
}
5461

5562
String idList = StringUtils.join(ids, ",");
5663
Integer idListSize = ids.size();

src/main/java/hudson/plugins/jira/JiraIssueUpdateBuilder.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,15 @@
1515
*/
1616
package hudson.plugins.jira;
1717

18+
import com.atlassian.jira.rest.client.api.RestClientException;
1819
import hudson.EnvVars;
1920
import hudson.Extension;
2021
import hudson.Util;
21-
import hudson.model.AbstractProject;
22-
import hudson.model.Job;
23-
import hudson.model.Result;
24-
import hudson.model.Run;
25-
import hudson.model.TaskListener;
22+
import hudson.model.*;
2623
import hudson.tasks.BuildStepDescriptor;
2724
import hudson.tasks.Builder;
2825
import hudson.util.FormValidation;
2926
import java.io.IOException;
30-
import java.util.concurrent.TimeoutException;
3127
import jenkins.tasks.SimpleBuildStep;
3228
import org.apache.commons.lang.StringUtils;
3329
import org.jenkinsci.Symbol;
@@ -105,9 +101,8 @@ public void perform(Run<?, ?> run, EnvVars env, TaskListener listener) throws In
105101
listener.getLogger().println(Messages.JiraIssueUpdateBuilder_SomeIssuesFailed());
106102
run.setResult(Result.UNSTABLE);
107103
}
108-
} catch (TimeoutException e) {
109-
listener.getLogger().println(Messages.JiraIssueUpdateBuilder_Failed());
110-
e.printStackTrace(listener.getLogger());
104+
} catch (RestClientException e) {
105+
listener.getLogger().println(e.getMessage());
111106
run.setResult(Result.FAILURE);
112107
}
113108
}

src/main/java/hudson/plugins/jira/JiraJobAction.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package hudson.plugins.jira;
22

3+
import com.atlassian.jira.rest.client.api.RestClientException;
34
import edu.umd.cs.findbugs.annotations.NonNull;
45
import edu.umd.cs.findbugs.annotations.Nullable;
56
import hudson.Extension;
@@ -127,8 +128,9 @@ public void onStarted(WorkflowRun workflowRun, TaskListener listener) {
127128
if (site != null) {
128129
try {
129130
setAction(parent, site);
130-
} catch (IOException e) {
131+
} catch (IOException | RestClientException e) {
131132
LOGGER.log(Level.WARNING, "Could not set JiraJobAction for <" + parent.getFullName() + ">", e);
133+
listener.getLogger().println(e.getMessage());
132134
}
133135
}
134136
}

0 commit comments

Comments
 (0)