本文介绍了如何将NodeLabelParameter插件中的参数与"build"一起使用. Jenkins工作流程的步骤的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个工作,它接受由NodeLabelParameter插件提供的节点"参数,我想通过构建"步骤从詹金斯的工作流程"工作中调用它.

I have a job that take a "Node" parameter provided by the NodeLabelParameter plugin, and I would like to call it from a jenkins "Workflow" job, via the "build" step.

当我将代码段生成器与构建工作"一起使用时,生成的代码是:

When I use the Snippet Generator with "Build a job", the generated code is :

build job: 'test job', parameters: [<object of type org.jvnet.jenkins.plugins.nodelabelparameter.NodeParameterValue>]

这当然是无效的.

我尝试了这一点(我在NodeLabelParameter插件代码中找到了这个构造函数):

I tried this (I found this constructor in the NodeLabelParameter plugin code):

build job: 'test job', parameters: [[new org.jvnet.jenkins.plugins.nodelabelparameter.NodeParameterValue('UPSTREAM_NODE', '', 'my_node')]]

但是由于以下异常,构建失败:

But the build fails with this exception :

java.lang.ClassCastException: org.jenkinsci.plugins.workflow.support.steps.build.BuildTriggerStep.parameters expects class hudson.model.ParameterValue but received class java.util.ArrayList
at org.jenkinsci.plugins.workflow.structs.DescribableHelper.coerce(DescribableHelper.java:250)
...

在工作流程作业中使用此类参数的正确语法是什么?

What is the correct syntax to use such a parameter from a workflow job ?

谢谢

推荐答案

例外是因为您有一组多余的方括号.试试

The exception is because you have an extraneous set of square brackets. Try

build job: 'test job', parameters: [new org.jvnet.jenkins.plugins.nodelabelparameter.NodeParameterValue('UPSTREAM_NODE', '', 'my_node')]

但是首选语法类似于

build job: 'test job', parameters: [[$class: 'NodeParameterValue', name: 'UPSTREAM_NODE', labels: ['my_node'], nodeEligibility: [$class: 'AllNodeEligibility']]]

这是我希望代码段生成器产生的结果,假设您正在使用此修复程序.如果是这样,并且代码段生成器仍然无法生成有效的代码,请提交错误报告.

which is what I would expect the Snippet Generator to produce, assuming you are running Workflow version 1.3 or higher with this fix. If you are, and the Snippet Generator still fails to produce valid code, please file a bug report.

这篇关于如何将NodeLabelParameter插件中的参数与"build"一起使用. Jenkins工作流程的步骤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 19:00