I'm working on a Jenkins plugin that 
implements org.jenkinsci.plugins.workflow.flow.GraphListener to monitor how 
a pipeline is progressing. It 
receives org.jenkinsci.plugins.workflow.graph.FlowNode objects. I would 
like to be able to report on which agent a particular FlowNode is running 
on.

How can I go from an instance of a FlowNode to 
its hudson.model.Computer, hudson.model.Node, or anything else that will 
tell me the agent's name? I am ok with assuming that the FlowNode is 
currently executing, or is contained inside a node{} block if it helps, but 
would prefer to keep it general.

I've so far tried browsing through the 
related FlowExecution, FlowExecutionOwner, Queue.Executable, and Subtask 
classes, but if it's in there I haven't found it.

The closest I've come so far is to use node.iterateEnclosingBlocks(). I can 
find FlowNodes where an agent was allocated 
with .getDisplayFunctionName().equals('node'), but not *which* agent was 
allocated. I thought the WorkspaceAction action may help since it has 
a getNode() method that should return the agent name as a string, but it 
returns nothing:
for (FlowNode enclosing : node.iterateEnclosingBlocks()) {
    WorkspaceAction ws = enclosing.getAction(WorkspaceAction.class);
    if (ws != null) {
        System.out.println(ws.getNode()); // outputs empty string 
    }
}

Can anyone direct me to the right methods/classes to get this information?


-- 
You received this message because you are subscribed to the Google Groups 
"Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-dev/b256bc33-9729-4c6f-8f37-f6cbf8e5aa46n%40googlegroups.com.

Reply via email to