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()) {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.
for a "stage" Step, the FlowNode (a StepStartNode) doesn't yet have a LabelAction associated with it.
I could compromise by using StepListener to get the start of a step and GraphListener to get the end of it, but only if the stage name can be found.
Given the FlowNode from GraphListener, is there a way to get to the StepContext?
The output is intended for humans, to whom FlowNode.id will be meaningless
If both listeners have access to the same node, I feel there must be some way of getting the same information.
if there's not a way of getting at that information from the flownode itself (and I'd still really like to know *why* that is the case)
https://javadoc.jenkins.io/plugin/workflow-api/org/jenkinsci/plugins/workflow/actions/WorkspaceAction.html#getNode-- ought to tell you the name of the agent running a `node` block, or the empty string in the case of a controller executor (typically ill-advised).
I'm working in a plugin with mvn hpi:run, which only has the single controller node.