简体   繁体   English

如何在詹金斯管道中使用参数化构建?

[英]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.

相关问题 参数化的管道构建詹金斯始终使用最后的构建参数。 如何解决这个问题? - Parameterized pipeline build jenkins always use last build parameters. How to fix this? Jenkins Pipeline 检查参数化构建是否真的参数化 - Jenkins Pipeline check if parameterized build is really parameterized 如何从詹金斯管道获取所有参数(参数化构建)? - How to get all parameters(Parameterized build) from jenkins pipeline? 如何在 Jenkins Pipeline 脚本中使用“参数化远程触发器插件”? - How to use “Parameterized Remote Trigger Plugin” in Jenkins Pipeline script? 如何在詹金斯管道中使用Artifactory Maven Build - How to use Artifactory Maven Build in Jenkins Pipeline 参数化管道构建可在詹金斯构建多个工作 - Parameterized pipeline build to build more than one job in jenkins 如何将参数传递到管道脚本但不使其成为 jenkins UI 中的参数化构建 - How do you pass parameter into a pipeline script but not make it a parameterized build in the jenkins UI Jenkins参数化管道失败 - Jenkins parameterized pipeline fail 如何在詹金斯(Jenkins)成功构建后触发参数化构建? - How to trigger parameterized build on successful build in Jenkins? Jenkins 参数化构建以使用键/值对 - Jenkins Parameterized build to use key/value pairs
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM