[英]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.