[英]How to reference the node paramater from the active choices reactive parameter in Jenkins
I basically want to drive a set of choice parameters based on the slave node parameter choice.我基本上想根据从节点参数选择来驱动一组选择参数。 I tried to use the active choices reactive plugin to point to the node choice like this:我尝试使用主动选择反应插件来指向这样的节点选择:
if (Node.contains("name_of_slave_node")) {
return ["you_chose_slave_node"]
} else {
return ["master"]
}
Nothing I do seems to work.我所做的一切似乎都不起作用。 I can use this type of logic and point to any other type of parameter and it works.我可以使用这种类型的逻辑并指向任何其他类型的参数并且它可以工作。 Im just a bit stumped as to where to go with this.我只是有点不知道该去哪里。 Could it be a limitation with the plugin or am I missing something with how the groovy is addressing the node parameter.这可能是插件的限制,还是我遗漏了 groovy 如何解决节点参数的问题。 I really appreciate any advice.我真的很感激任何建议。
It can be hard to get your head around how the plug-in works. 很难理解插件的工作原理。 Even now I still get surprised by all the cases users apply the plug-in, and the different ways they use it. 即使到现在,我仍然对用户使用该插件的所有情况以及他们使用它的不同方式感到惊讶。
You can definitely do what you want. 您绝对可以做您想做的。 The plug-in executes a Groovy script that must return an array with the values to be displayed on the UI. 该插件执行Groovy脚本,该脚本必须返回一个数组,其中包含要在UI上显示的值。 You also have some helper variables that the plug-in tries to make available for you. 您还可以使用一些帮助程序变量,插件会尝试将这些变量提供给您。 One of these variables is the jenkinsProject . 这些变量之一是jenkinsProject 。
If in your project you assigned a label, then programmatically you can return values based on the node label assigned to your project (or to the node object...). 如果在项目中分配了标签,则可以以编程方式基于分配给项目(或节点对象...)的节点标签返回值。
Here's a very simple example. 这是一个非常简单的示例。
assignedNode = jenkinsProject.getAssignedLabelString()
list = []
if (assignedNode == null) {
// do something
} else if (assignedNode.equals('abc')) {
// ...
}
return list
Here assignedNode will have the string name of the node, or null if none. 在这里, signedNode将具有节点的字符串名称;如果没有,则为null。 If you use instead jenkinsProject.getAssignedLabel() , then you will have not a String, but a Label . 如果改为使用jenkinsProject.getAssignedLabel() ,则您将没有String,而是Label 。
If you need further customization, the best way is to dive into the Java API, then build your Groovy script from the bottom up. 如果需要进一步的自定义,最好的方法是深入Java API,然后从下至上构建Groovy脚本。 Or try finding examples online (there are many for Jenkins and Groovy) and adapt them to your parameter. 或尝试在线查找示例(Jenkins和Groovy有很多示例),并根据您的参数进行调整。
Hope that helps, Bruno 希望能有所帮助,布鲁诺
I managed to cobble something together yesterday that accomplishes what you want in Jenkin's freestyle jobs.昨天我设法拼凑了一些东西,在詹金的自由泳工作中实现了你想要的。 For reference though, it seems like what we want to accomplish is easier done with Jenkin's pipelines (see Active Choices Reactive Reference Parameter in jenkins pipeline )不过作为参考,我们想要完成的工作似乎更容易使用 Jenkin 的管道完成(请参阅jenkins 管道中的 Active Choices Reactive Reference Parameter )
First, know that the Active choices reactive plugin does not detect any changes in the NodeLabel node parameter choice.首先,要知道 Active choice 反应式插件不会检测 NodeLabel 节点参数选择中的任何更改。 You are not going to be able to dynamicially adjust your reactive parameters based on the node/label parameter choice.您将无法根据节点/标签参数选择动态调整反应参数。 (perhaps this is because the Node parameter simply prepares a separate job for each node chosen and in that way the Node parameter is more like a build time choice instead of a dynamic one) But I have a workaround. (也许这是因为 Node 参数只是为每个选择的节点准备了一个单独的作业,这样 Node 参数更像是一个构建时间选择而不是动态选择)但我有一个解决方法。
On the NodeLabel documentation, they specify that the plugin works with the Parameterized Trigger Plugin, see Using the Parameterized Trigger Plugin .在 NodeLabel 文档中,他们指定插件与参数化触发器插件一起使用,请参阅使用参数化触发器插件。 This is going to be key.这将是关键。
job工作 | list of parameters参数列表 |
---|---|
master掌握 | - active choice parameter (node) - 主动选择参数(节点) - foo - 富 - bar - 酒吧 |
copy复制 | - NodeLabel parameter - 节点标签参数 - active choice parameter (node) - 主动选择参数(节点) - foo - 富 - bar - 酒吧 |
This real NodeLabel parameter will take in the active choice parameter from the master job这个真正的 NodeLabel 参数将从主作业中获取活动选择参数 to the end user, this node standin active parameter on the master job will react and act just like any other parameter.对于最终用户,主作业上的此节点备用活动参数将像任何其他参数一样做出反应和动作。 The node choice in the first box changes the results in the second box.第一个框中的节点选择会更改第二个框中的结果。 In the configurtation of the master job we then pass our parameters like such, using the "parameterized trigger plugin" from above.在主作业的配置中,我们然后像这样传递我们的参数,使用上面的“参数化触发器插件”。
Just make sure the scoped/copy job is doing the real work and you should be good to go.只要确保范围/复制工作正在做真正的工作,你应该很高兴。 The master/wrap job's purpose is only to act as a nice visual wrapper to the node parameter and its subsequent choices that takes advantage of the Active choice reactive parameter plugin's capabilities.主/包装作业的目的只是充当节点参数及其后续选择的良好视觉包装器,这些选择利用了主动选择反应参数插件的功能。 Finally, it passes its results and responsibilities to the scoped/copy job.最后,它将其结果和职责传递给作用域/复制作业。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.