如何将 NodeLabelParameter 插件中的参数与“构建"一起使用詹金斯工作流程的步骤 [英] How to use a parameter from NodeLabelParameter Plugin with the "build" step of Jenkins Workflow

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

问题描述

我有一个作业,它采用 NodeLabelParameter 插件提供的节点"参数,我想通过构建"步骤从 jenkins工作流"作业中调用它.

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 插件中的参数与“构建"一起使用詹金斯工作流程的步骤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆