Skip to content

Commit

Permalink
ENTERPRISE-728: Log complete exception stacktrace to the console.
Browse files Browse the repository at this point in the history
While the stacktrace isn't available in a job output,
it will be visible in jenkins logs.
Moreover, the previous change captures exception's cause message,
so the user should have a clue what's happening.
  • Loading branch information
jumarko committed Dec 6, 2018
1 parent 74d6be6 commit a9bcd47
Showing 1 changed file with 19 additions and 3 deletions.
Expand Up @@ -11,9 +11,9 @@
import com.cloudbees.plugins.credentials.common.UsernamePasswordCredentials;
import com.cloudbees.plugins.credentials.domains.DomainRequirement;
import hudson.EnvVars;
import hudson.Launcher;
import hudson.Extension;
import hudson.FilePath;
import hudson.Launcher;
import hudson.console.HyperlinkNote;
import hudson.model.Item;
import hudson.model.Queue;
Expand All @@ -22,15 +22,23 @@
import hudson.model.TaskListener;
import hudson.model.queue.Tasks;
import hudson.security.ACL;
import hudson.tasks.Builder;
import hudson.tasks.BuildStepDescriptor;
import hudson.tasks.Builder;
import hudson.util.FormValidation;
import hudson.util.ListBoxModel;
import jenkins.model.Jenkins;
import jenkins.tasks.SimpleBuildStep;
import net.sf.json.JSONObject;
import org.jenkinsci.Symbol;
import org.jenkinsci.plugins.codescene.Domain.*;
import org.jenkinsci.plugins.codescene.Domain.Branch;
import org.jenkinsci.plugins.codescene.Domain.CodeSceneUser;
import org.jenkinsci.plugins.codescene.Domain.Commit;
import org.jenkinsci.plugins.codescene.Domain.CommitRange;
import org.jenkinsci.plugins.codescene.Domain.Commits;
import org.jenkinsci.plugins.codescene.Domain.Configuration;
import org.jenkinsci.plugins.codescene.Domain.DeltaAnalysisResult;
import org.jenkinsci.plugins.codescene.Domain.RemoteAnalysisException;
import org.jenkinsci.plugins.codescene.Domain.Repository;
import org.kohsuke.stapler.AncestorInPath;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.DataBoundSetter;
Expand All @@ -44,8 +52,13 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

public class CodeSceneBuilder extends Builder implements SimpleBuildStep {

private static final Logger logger = Logger.getLogger(CodeSceneBuilder.class.getName());

private static final int DEFAULT_RISK_THRESHOLD = 7;
// default is the same as in codescene rest api and shouldn't be changed
private static final int DEFAULT_COUPLING_THRESHOLD_PERCENT = 80;
Expand Down Expand Up @@ -293,6 +306,9 @@ public void perform(Run<?, ?> build, FilePath workspace, Launcher launcher, Task

} catch (RemoteAnalysisException e) {
listener.error("Remote failure as CodeScene couldn't perform the delta analysis: %s", e);
// This is necessary to log the complete stacktrace - listener only shows exception message
// Note: this log is visible only in the jenkins logs, not in the job's console log.
logger.log(Level.WARNING, "Remote failure as CodeScene couldn't perform the delta analysis: %s", e);
build.setResult(buildResultForFailedAnalysisDependsOn(letBuildPassOnFailedAnalysis));
} catch (InterruptedException | IOException e) {
listener.error("Failed to run delta analysis: %s", e);
Expand Down

0 comments on commit a9bcd47

Please sign in to comment.