[英]How to use parameterized build in jenkins pipeline?
I am having these lines in my Jenkinsfile: 我的Jenkinsfile中有这些行:
parameters {
string(name: 'DATABASE', defaultValue: 'jenkinsdatabase',
description: 'The name of the database')
}
(...)
Now I want to use the value of ${params.DATABASE} in a step of a stage eg 现在,我想在一个阶段的步骤中使用$ {params.DATABASE}的值,例如
sh 'mysql --user ${USER} -p${PASSWORD} --host ${HOST} -e "DROP DATABASE IF EXISTS ${params.DATABASE};CREATE DATABASE ${params.DATABASE} DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci; commit;";export GRADLE_OPTS="-Xms1536m -Xmx1536m"'
But this ends with a exeception: Bad substitution 但这以一种观念结束: 不良替代
Can anybody help me? 有谁能够帮助我?
Your sh
script body uses single quotes around it. 您的
sh
脚本主体使用单引号引起来。
sh '...'
Since these are single quotes, string interpolation will not occur. 由于这些是单引号,因此不会发生字符串插值 。 This means that all of your
$
strings will use the shell variable substitution instead of the Groovy substitution. 这意味着您所有的
$
字符串都将使用shell变量替换而不是Groovy替换。 You are getting a Bad substitution in the shell because the shell won't be able to substitute ${params.DATABASE}
because that is an invalid shell substitution. 您在shell中得到错误的替换 ,因为shell无法替换
${params.DATABASE}
因为这是无效的shell替换。
params
is a Groovy variable, so switching your single quotes to double quotes will perform string interpolation of the variables. params
是一个Groovy变量,因此将单引号切换为双引号将对变量进行字符串插值。
sh "..."
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.