|
@@ -7,6 +7,8 @@ |
|
|
import hudson.model.Result; |
|
|
import hudson.model.AbstractBuild; |
|
|
import hudson.model.AbstractProject; |
|
|
import hudson.model.Run; |
|
|
import hudson.model.TaskListener; |
|
|
import hudson.plugins.logparser.action.LogParserProjectAction; |
|
|
import hudson.tasks.BuildStepDescriptor; |
|
|
import hudson.tasks.BuildStepMonitor; |
|
@@ -19,11 +21,12 @@ |
|
|
import java.util.logging.Level; |
|
|
import java.util.logging.Logger; |
|
|
|
|
|
import jenkins.tasks.SimpleBuildStep; |
|
|
import net.sf.json.JSONObject; |
|
|
|
|
|
import org.kohsuke.stapler.StaplerRequest; |
|
|
|
|
|
public class LogParserPublisher extends Recorder implements Serializable { |
|
|
public class LogParserPublisher extends Recorder implements SimpleBuildStep, Serializable { |
|
|
private static final long serialVersionUID = 1L; |
|
|
public final boolean unstableOnWarning; |
|
|
public final boolean failBuildOnError; |
|
@@ -67,58 +70,61 @@ public boolean prebuild(final AbstractBuild<?, ?> build, |
|
|
return true; |
|
|
} |
|
|
|
|
|
@Deprecated |
|
|
@Override |
|
|
public boolean perform(final AbstractBuild<?, ?> build, |
|
|
final Launcher launcher, final BuildListener listener) |
|
|
public boolean perform(final AbstractBuild<?, ?> build, final Launcher launcher, final BuildListener listener) |
|
|
throws InterruptedException, IOException { |
|
|
|
|
|
this.perform((Run<?, ?>) build, build.getWorkspace(), launcher, listener); |
|
|
return true; |
|
|
} |
|
|
|
|
|
@Override |
|
|
public void perform(Run<?, ?> run, FilePath workspace, Launcher launcher, TaskListener listener) throws |
|
|
InterruptedException, IOException { |
|
|
|
|
|
final Logger logger = Logger.getLogger(getClass().getName()); |
|
|
LogParserResult result = new LogParserResult(); |
|
|
try { |
|
|
// Create a parser with the parsing rules as configured : colors, |
|
|
// regular expressions, etc. |
|
|
boolean preformattedHtml = !((DescriptorImpl) getDescriptor()) |
|
|
.getLegacyFormatting(); |
|
|
// Create a parser with the parsing rules as configured : colors, regular expressions, etc. |
|
|
boolean preformattedHtml = !((DescriptorImpl) getDescriptor()).getLegacyFormatting(); |
|
|
final FilePath parsingRulesFile; |
|
|
if (useProjectRule) { |
|
|
parsingRulesFile = new FilePath(build.getWorkspace(), |
|
|
projectRulePath); |
|
|
parsingRulesFile = new FilePath(workspace, projectRulePath); |
|
|
} else { |
|
|
parsingRulesFile = new FilePath(new File(parsingRulesPath)); |
|
|
} |
|
|
final LogParserParser parser = new LogParserParser( |
|
|
parsingRulesFile, preformattedHtml, launcher.getChannel()); |
|
|
final LogParserParser parser = new LogParserParser(parsingRulesFile, preformattedHtml, launcher.getChannel()); |
|
|
// Parse the build's log according to these rules and get the result |
|
|
result = parser.parseLog(build); |
|
|
result = parser.parseLog(run); |
|
|
|
|
|
// Mark build as failed/unstable if necessary |
|
|
if (this.failBuildOnError && result.getTotalErrors() > 0) { |
|
|
build.setResult(Result.FAILURE); |
|
|
run.setResult(Result.FAILURE); |
|
|
} else if (this.unstableOnWarning && result.getTotalWarnings() > 0) { |
|
|
build.setResult(Result.UNSTABLE); |
|
|
run.setResult(Result.UNSTABLE); |
|
|
} |
|
|
} catch (IOException e) { |
|
|
// Failure to parse should not fail the build - but should be |
|
|
// handled as a serious error. |
|
|
// This should catch all process problems during parsing, including |
|
|
// parser file not found.. |
|
|
logger.log(Level.SEVERE, LogParserConsts.CANNOT_PARSE + build, e); |
|
|
logger.log(Level.SEVERE, LogParserConsts.CANNOT_PARSE + run, e); |
|
|
result.setFailedToParseError(e.toString()); |
|
|
} catch (NullPointerException e) { |
|
|
// in case the rules path is null |
|
|
logger.log(Level.SEVERE, LogParserConsts.CANNOT_PARSE + build, e); |
|
|
logger.log(Level.SEVERE, LogParserConsts.CANNOT_PARSE + run, e); |
|
|
result.setFailedToParseError(e.toString()); |
|
|
build.setResult(Result.ABORTED); |
|
|
run.setResult(Result.ABORTED); |
|
|
} catch (InterruptedException e) { |
|
|
logger.log(Level.SEVERE, LogParserConsts.CANNOT_PARSE + build, e); |
|
|
logger.log(Level.SEVERE, LogParserConsts.CANNOT_PARSE + run, e); |
|
|
result.setFailedToParseError(e.toString()); |
|
|
build.setResult(Result.ABORTED); |
|
|
run.setResult(Result.ABORTED); |
|
|
} |
|
|
|
|
|
// Add an action created with the above results |
|
|
final LogParserAction action = new LogParserAction(build, result); |
|
|
build.getActions().add(0, action); |
|
|
|
|
|
return true; |
|
|
final LogParserAction action = new LogParserAction(run, result); |
|
|
run.addAction(action); |
|
|
} |
|
|
|
|
|
@Override |
|
|