Skip to content

Commit

Permalink
JENKINS-70090 - Add warning log message if log/report html files are …
Browse files Browse the repository at this point in the history
…not found (#60)

* Add a warning log message when log and report files are not found

* Take outputdir into account when checking if log file exists

* Remove commented line
  • Loading branch information
asimell committed Jul 5, 2023
1 parent 90aafd7 commit 53dac7d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
14 changes: 11 additions & 3 deletions src/main/java/hudson/plugins/robot/RobotPublisher.java
Expand Up @@ -36,6 +36,7 @@
import java.util.ArrayList;
import java.util.Collection;

import javax.annotation.Nonnull;
import javax.servlet.ServletException;

import jenkins.tasks.SimpleBuildStep;
Expand Down Expand Up @@ -249,25 +250,32 @@ protected RobotResult parse(String expandedTestResults, String expandedLogFileNa
* {@inheritDoc}
*/
@Override
public void perform(Run<?, ?> build, FilePath workspace, Launcher launcher, TaskListener listener) throws InterruptedException, IOException {
public void perform(Run<?, ?> build, @Nonnull FilePath workspace, @Nonnull EnvVars buildEnv, @Nonnull Launcher launcher, @Nonnull TaskListener listener) throws InterruptedException, IOException {
if (build.getResult() != Result.ABORTED) {
PrintStream logger = listener.getLogger();
logger.println(Messages.robot_publisher_started());
logger.println(Messages.robot_publisher_parsing());
RobotResult result;

try {
EnvVars buildEnv = build.getEnvironment(listener);
String expandedOutputFileName = buildEnv.expand(getOutputFileName());
String expandedOutputPath = buildEnv.expand(getOutputPath());
String expandedReportFileName = buildEnv.expand(getReportFileName());
String expandedLogFileName = buildEnv.expand(getLogFileName());
String logFileJavascripts = trimSuffix(expandedLogFileName) + ".js";

result = parse(expandedOutputFileName, expandedLogFileName, expandedReportFileName, expandedOutputPath, build, workspace, launcher, listener);

logger.println(Messages.robot_publisher_done());

// Check if log and report files exist
FilePath outputDir = new FilePath(workspace, expandedOutputPath);
if (!new FilePath(outputDir, expandedLogFileName).exists()) {
logger.println(Messages.robot_publisher_file_not_found() + " " + expandedLogFileName);
}
if (!new FilePath(outputDir, expandedReportFileName).exists()) {
logger.println(Messages.robot_publisher_file_not_found() + " " + expandedReportFileName);
}

if (!DEFAULT_JENKINS_ARCHIVE_DIR.equalsIgnoreCase(getArchiveDirName())) {
logger.println(Messages.robot_publisher_copying());
//Save configured Robot files (including split output) to build dir
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/hudson/plugins/robot/RobotStepExecution.java
Expand Up @@ -2,13 +2,12 @@

import java.util.logging.Logger;

import hudson.EnvVars;
import org.jenkinsci.plugins.workflow.steps.StepContext;
import org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution;

import hudson.FilePath;
import hudson.Launcher;
import hudson.matrix.MatrixBuild;
import hudson.model.BuildListener;
import hudson.model.Run;
import hudson.model.TaskListener;

Expand All @@ -29,7 +28,7 @@ public class RobotStepExecution extends SynchronousNonBlockingStepExecution<Void
FilePath workspace = getContext().get(FilePath.class);
workspace.mkdirs();
RobotPublisher rp = new RobotPublisher(step.getArchiveDirName(), step.getOutputPath(), step.getOutputFileName(), step.getDisableArchiveOutput(), step.getReportFileName(), step.getLogFileName(), step.getPassThreshold(), step.getUnstableThreshold(), step.getOnlyCritical(), step.getOtherFiles(), step.getEnableCache(), step.getOverwriteXAxisLabel());
rp.perform(getContext().get(Run.class), workspace, getContext().get(Launcher.class), getContext().get(TaskListener.class));
rp.perform(getContext().get(Run.class), workspace, getContext().get(EnvVars.class), getContext().get(Launcher.class), getContext().get(TaskListener.class));
return null;
}

Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/hudson/plugins/robot/Messages.properties
Expand Up @@ -23,6 +23,8 @@ robot.publisher.finished=Done publishing Robot results.
robot.publisher.done= Done!
robot.publisher.fail= Failed!

robot.publisher.file_not_found=WARNING! Could not find file:

robot.config.percentvalidation=Entry must be percentage value between 0-100

robot.trendgraph.passed=Passed
Expand Down

0 comments on commit 53dac7d

Please sign in to comment.