如何检查构建参数在Jenkinsfile中是否可用 [英] How to check if build parameter is available in Jenkinsfile

查看:532
本文介绍了如何检查构建参数在Jenkinsfile中是否可用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个管道脚本,可以使用和不使用参数.所以我必须检查参数是否可用.

I have a pipeline script that should work with and without parameters. So I have to check if the parameter is available.

我尝试了if(getBinding().hasVariable("myparameter")),但这会导致异常

I tried if(getBinding().hasVariable("myparameter")) but this leads to an Exception

org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: Scripts not permitted to use method groovy.lang.Binding getVariables

还有另一种检查作业是否已参数化的方法吗?

Is there another way to check if the job is parameterized?

推荐答案

较新的版本通过params变量使参数可用.如果未定义该参数,则它将恢复为配置的默认值(另请参见此处).

Newer versions make the parameters available through the params variable. If the parameter is not defined, it falls back to the configured default (see also here).

这篇关于如何检查构建参数在Jenkinsfile中是否可用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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