Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
732 views
in Technique[技术] by (71.8m points)

groovy - How to use a parameter from NodeLabelParameter Plugin with the "build" step of Jenkins Workflow

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>]

Of course this is not valid.

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 ?

Thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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')]

However the preferred syntax is something like

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...