Skip to content

Commit

Permalink
Test results from pipe without workspace (#167)
Browse files Browse the repository at this point in the history
tech : test result are not received in workflow job - when job has workspace action with workspace =null (because of strange configuration of node)
  • Loading branch information
radislavB committed Jan 16, 2019
1 parent 7f155a5 commit ae4760f
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,11 @@
import hudson.matrix.MatrixConfiguration;
import hudson.matrix.MatrixRun;
import hudson.model.AbstractBuild;
import hudson.model.Computer;
import hudson.model.Result;
import hudson.model.Run;
import jenkins.model.Jenkins;
import org.apache.commons.lang.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.jenkinsci.plugins.workflow.actions.LabelAction;
Expand All @@ -44,6 +47,7 @@
import org.jenkinsci.plugins.workflow.graph.FlowStartNode;
import org.jenkinsci.plugins.workflow.job.WorkflowRun;

import java.io.File;
import java.io.IOException;

/**
Expand Down Expand Up @@ -89,21 +93,52 @@ public static FilePath getWorkspace(Run<?, ?> run) {
if (fe != null) {
FlowGraphWalker w = new FlowGraphWalker(fe);
for (FlowNode n : w) {
if (n instanceof StepStartNode) {
WorkspaceAction action = n.getAction(WorkspaceAction.class);
if (action != null) {
return action.getWorkspace();
WorkspaceAction action = n.getAction(WorkspaceAction.class);
if (action != null) {
FilePath workspace = action.getWorkspace();
if (workspace == null) {
workspace = handleWorkspaceActionWithoutWorkspace(n, action);
}
return workspace;
}
}
logger.error("BuildHandlerUtils.getWorkspace - missing WorkspaceAction on WorkflowRun.");
}
}

logger.error("BuildHandlerUtils.getWorkspace - run is not handled. Run type : " + run.getClass());
return null;
}

private static FilePath handleWorkspaceActionWithoutWorkspace(FlowNode n, WorkspaceAction action) {
logger.error("Found WorkspaceAction without workspace");
logger.warn("Node getPath = " + action.getPath());
logger.warn("Node getNode = " + action.getNode());
FilePath workspace = null;

//check if computer can be found - only for diagnostic purpose
if (action.getNode() != null) {
try {
Jenkins j = Jenkins.getInstance();
Computer c = j.getComputer(action.getNode());
if (c != null) {
logger.warn("Computer is found : " + c.getDisplayName());
} else {
logger.warn("Computer is not found");
}
} catch (Exception e) {
logger.warn("Failed to find computer : " + e.getMessage() + ", error type : " + e.getClass().getName());
}
}

if (StringUtils.isNotEmpty(action.getPath())) {
logger.warn("Node getPath is not empty, return getPath as workspace");
workspace = new FilePath(new File(action.getPath()));
} else {
logger.warn("Node getPath is empty, return workspace = null");
}
return workspace;
}

public static String getBuildCiId(Run run) {
return String.valueOf(run.getNumber());
// YG temporary disabling the support for fluid build number until Octane supports it
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,13 @@ public TestResultContainer getTestResults(Run<?, ?> run, HPRunnerType hpRunnerTy
if (resultFile.exists()) {
logger.debug("JUnit result report found");
ResultFields detectedFields = getResultFields(run, hpRunnerType, isLoadRunnerProject);
FilePath filePath = BuildHandlerUtils.getWorkspace(run).act(new GetJUnitTestResults(run, Collections.singletonList(resultFile), false, hpRunnerType, jenkinsRootUrl));
FilePath workspace = BuildHandlerUtils.getWorkspace(run);
if (workspace == null) {
logger.error("Received null workspace : " + run);
return null;
}

FilePath filePath = workspace.act(new GetJUnitTestResults(run, Collections.singletonList(resultFile), false, hpRunnerType, jenkinsRootUrl));
return new TestResultContainer(new ObjectStreamIterator<>(filePath), detectedFields);
} else {
//avoid java.lang.NoClassDefFoundError when maven plugin is not present
Expand Down

0 comments on commit ae4760f

Please sign in to comment.