Node info in Jenkins pipeline environment

55 views
Skip to first unread message

conso...@gmail.com

unread,
Jun 14, 2018, 1:11:51 AM6/14/18
to Jenkins Developers
I'm write a jenkins plugin to get some infos of jobs,  i want to get the node info which the job running on.  now i have the code by extend RunListener,  the code works fine in free style project, but in pipeline, the EnvVars not contains NODE_NAME,  so it not works.

@Override
public void onCompleted(Run<?, ?> run, TaskListener listener) { 
  Node node = run.getExecutor().getOwner().getNode();
  String nodeName = node.getNodeName();
  EnvVars environment = run.getEnvironment(listener);
  if (nodeName.equals("") && environment.containsKey("NODE_NAME")) {
      nodeName = environment.get("NODE_NAME");
  }
}
But in the code workflow-durable-task-step-plugin ,  the NODE_NAME is put in the EnvVars. I don't know why this happened and is there any way  to get node info.  

Ullrich Hafner

unread,
Jun 14, 2018, 3:39:20 AM6/14/18
to Jenkins Developers
In my plugin I’m simply using build.getExecutor().getOwner().getName(). Note that getOwner() might return null.

--
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 jenkinsci-de...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/c17fd3d7-86a6-4622-8f34-1a6c95feac05%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

signature.asc

bill jonse

unread,
Jun 14, 2018, 5:09:24 AM6/14/18
to Jenkins Developers
Thanks, but it can not get node info in pipeline.

在 2018年6月14日星期四 UTC+8下午3:39:20,Ullrich Hafner写道:
在 2018年6月14日星期四 UTC+8下午3:39:20,Ullrich Hafner写道:
在 2018年6月14日星期四 UTC+8下午3:39:20,Ullrich Hafner写道:
在 2018年6月14日星期四 UTC+8下午3:39:20,Ullrich Hafner写道:
在 2018年6月14日星期四 UTC+8下午3:39:20,Ullrich Hafner写道:

Markus Winter

unread,
Jun 14, 2018, 10:58:25 AM6/14/18
to jenkin...@googlegroups.com

In pipeline, the information is added to ENV_VARS only for the time that the pipeline really is using an executor on a node. So you will not be able to collect this information in the onCompleted method of a RunListener. Also consider that a pipeline can run on multiple nodes.

You might consider implementing an ExecutorListener.

Jesse Glick

unread,
Jun 15, 2018, 4:01:09 PM6/15/18
to Jenkins Dev
On Thu, Jun 14, 2018 at 10:58 AM, Markus Winter <m_wi...@gmx.de> wrote:
> In pipeline, the information is added to ENV_VARS only for the time that the
> pipeline really is using an executor on a node. So you will not be able to
> collect this information in the onCompleted method of a RunListener. Also
> consider that a pipeline can run on multiple nodes.

Right, the problem statement does not even make sense. What you _can_
collect is a possibly empty set of nodes a build used.

> You might consider implementing an ExecutorListener.

You can use `RunListener`, just get the `FlowNode` graph and look for
those nodes with a `WorkspaceAction` attached.

bill jonse

unread,
Jun 19, 2018, 4:11:24 AM6/19/18
to jenkin...@googlegroups.com
ok, thanks for your reply

Jesse Glick <jgl...@cloudbees.com> 于2018年6月16日周六 上午4:01写道:
--
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 jenkinsci-de...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages