Skip to content

Commit

Permalink
Add support for Workflow build processes.
Browse files Browse the repository at this point in the history
  • Loading branch information
nosmo committed Jan 23, 2019
1 parent 0aa3bc4 commit f7b4755
Showing 1 changed file with 48 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,17 @@
import org.jenkinsci.plugins.ghprb.extensions.GhprbExtension;
import org.jenkinsci.plugins.ghprb.extensions.GhprbExtensionDescriptor;
import org.jenkinsci.plugins.ghprb.extensions.GhprbProjectExtension;
import org.jenkinsci.plugins.workflow.job.WorkflowRun;

import org.jenkinsci.plugins.workflow.graph.FlowGraphWalker;
import org.jenkinsci.plugins.workflow.graph.FlowNode;
import org.jenkinsci.plugins.workflow.graph.BlockStartNode;
import org.jenkinsci.plugins.workflow.flow.FlowExecution;
import org.jenkinsci.plugins.workflow.actions.WorkspaceAction;

import org.kohsuke.stapler.DataBoundConstructor;


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

Expand Down Expand Up @@ -42,9 +51,45 @@ public String postBuildComment(Run<?, ?> build, TaskListener listener) {

try {
String content = null;
if (build instanceof Build<?, ?>) {
final FilePath workspace = ((Build<?, ?>) build).getWorkspace();
final FilePath path = workspace.child(scriptFilePathResolved);
FilePath workspace;
FilePath path;

if (build instanceof WorkflowRun) {
FlowExecution exec = ((WorkflowRun) build).getExecution();
if (exec == null) {
listener.getLogger().println("build was instanceof WorkflowRun but executor was null");
} else {
FlowGraphWalker w = new FlowGraphWalker(exec);
for (FlowNode n : w) {
if (n instanceof BlockStartNode) {
WorkspaceAction action = n.getAction(WorkspaceAction.class);
if (action != null) {
String node = action.getNode().toString();
String nodepath = action.getPath().toString();
listener.getLogger().println("Remote path is " + node + ":" + nodepath + "\n");

if (action.getWorkspace() == null) {
continue;
}

path = action.getWorkspace().child(scriptFilePathResolved);

if (path.exists()) {
content = path.readToString();
} else {
listener.getLogger().println(
"Didn't find comment file in workspace at " + path.absolutize().getRemote()
+ ", falling back to file operations on master.\n"
);
}

}
}
}
}
} else if (build instanceof Build<?, ?>) {
workspace = ((Build<?, ?>) build).getWorkspace();
path = workspace.child(scriptFilePathResolved);

if (path.exists()) {
content = path.readToString();
Expand Down

0 comments on commit f7b4755

Please sign in to comment.