简体   繁体   English

从master检索Jenkins节点变量

[英]Retrieving Jenkins node variables from master

So my google-fu has failed me and the Jenkins O'Reilly book isn't helping either. 因此,我的Google-fu让我失败了,而詹金斯·奥莱利的书也无济于事。

I have a Jenkins setup with a master and 20-odd nodes. 我有一个具有主节点和20多个节点的Jenkins设置。 I make heavy use of custom environment variables on the nodes, as many of them perform similar tasks, only slightly different platforms. 我在节点上大量使用了自定义环境变量,因为它们中的许多执行相似的任务,只是平台略有不同。

I'm now in a position that I have a job that runs on the master (by necessity), which needs to know certain node properties for any given node, including some of the environment variables that I've set up. 现在,我的工作是在主服务器上运行(必要时),该工作需要知道任何给定节点的某些节点属性,包括我设置的一些环境变量。

Is there any way to reference these? 有什么办法可以引用这些吗? My alternative seems to be to have hundreds of environment variables in the master in the form node1_var1, node2_var1, node1_var2, node2_var2 etc., which just seems messy. 我的替代方法似乎是在母版中以node1_var1,node2_var1,node1_var2,node2_var2等形式存在数百个环境变量,这似乎有些混乱。 The master clearly has knowledge of the variables, as that's where the configuration for them is done, but I just can't find a way to specify them in a job. 大师显然了解变量,因为它们是在变量中完成的配置,但是我只是找不到在工作中指定变量的方法。

Any help (or ridicule and pointing out of obvious answers) much appreciated... 非常感谢任何帮助(或嘲笑和指出明显的答案)...

Here's a simple Groovy script that prints the list of environment variables for each slave: 这是一个简单的Groovy脚本,该脚本为每个从属打印环境变量列表:

for (slave in jenkins.model.Jenkins.instance.slaves) {
  println(slave.name + ": ")
  def props = slave.nodeProperties.getAll(hudson.slaves.EnvironmentVariablesNodeProperty.class)
  for (prop in props) {
    for (envvar in prop.envVars) {
      println envvar.key + " -> " + envvar.value
    }
  }
}

Warning: I am not an experienced Groovy programmer, so I may not be using the appropriate idioms of Groovy. 警告:我不是经验丰富的Groovy程序员,因此我可能没有使用Groovy的适当习惯用法。

You can run this from the Jenkins script console in order to experiment. 您可以从Jenkins脚本控制台运行此命令以进行实验。 You can also run a "System Groovy Script" as a build step. 您也可以运行“ System Groovy脚本”作为构建步骤。 Both of the above require the Groovy plugin . 以上两个都需要Groovy插件 If you don't use Groovy in your job, you could use this script to write a properties file that you load in the part of your build that does the real work. 如果您在工作中不使用Groovy,则可以使用此脚本编写一个属性文件,该文件将在实际工作的构建部分中加载。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用Groovy从Jenkins master访问节点从属文件 - Access files on a node slave from Jenkins master using Groovy 詹金斯:主节点在从属节点上看不到更改的环境变量 - Jenkins: Master node doesn't see changed environment variables on slave node 如何从主服务器中查找jenkins节点的IP地址 - How to find the ip address of a jenkins node from the master 如何将构建XML从Master复制到Jenkins中的Slave节点? - How to copy build XMLs from Master to the Slave node in Jenkins? 无法在 Jenkins 2.235 中从主节点 ssh 到从节点 - Cannot ssh from master to slave node in Jenkins 2.235 Jenkins 主从节点配置 - Jenkins master and slave node configuration 访问Cloudbees Jenkins主节点 - Access Cloudbees Jenkins master node 在我的 CiCD 管道中,从从 Jenkins 节点(Windows 节点)到主 Jenkins 节点(Linux 节点)的通信在作业执行过程中中断 - In my CiCD pipeline , communication from Slave Jenkins node(Windows node) to Master Jenkins node(Linux node) breaks in middle of job execution Jenkins 从主节点与 Git 连接,但不与从节点连接(权限被拒绝(公钥)) - Jenkins connect with Git from MAster node but not with Slave node (Permission denied (publickey)) 从 Node.js 访问 Jenkins 凭证环境变量 - Access Jenkins Credentials Environment Variables from Node.js
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM