How to use parameter from NodeLabelParameter Plugin with Jenkins Workflow "build" step

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

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

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

Of course, this is not true.

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

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 for using such a parameter from a workflow job?

thank

+4
source share
1 answer

, .

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

Snippet, , Workflow 1.3 . , Snippet - , .

+6

Source: https://habr.com/ru/post/1583989/


All Articles