本文介绍了如何检查 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 中的构建参数是否可用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 01:24