Jenkins Groovy:将参数转换为大写

时间:2019-03-01 21:39:40

标签: java jenkins groovy

如何将参数字符串转换为大写并在我的Jenkins文件中使用?

def parameters = [:]

// I get all the parameters from an ini file here and one of the parameter 'NAME' has its value in lowercase.

stage('example')
{
    echo 'converting parameter to uppercase'
    def a = ${parameters['NAME']}.toUpperCase()
    echo "${a}";
    bat "example.bat arg1 ${a}"
}

// THis is giving me some huge error when I run my Jenkins job with these lines in my file

2 个答案:

答案 0 :(得分:0)

怎么了?
可能:Groovy不确定“ $ {parameters ['NAME']}”是否为字符串。首先尝试强制执行,然后执行.toUpperCase:

def a = $ {parameters ['NAME']}。toString()。toUpperCase();

def a = parameters ['NAME']。toString()。toUpperCase();

答案 1 :(得分:0)

$ {}是字符串插值所必需的。以下链接应有帮助。

http://docs.groovy-lang.org/latest/html/documentation/#_string_interpolation