[英]Bad substitution when passing parameter to shell script in Jenkins
I'm attempting to pass value of a variable by setting the stdOut of a shell script.我试图通过设置 shell 脚本的 stdOut 来传递变量的值。 However in The console of Jenkins displays of followings:但是在 Jenkins 的控制台中显示以下内容:
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Feature Segunda)
[Pipeline] echo
${params.Segunda}
[Pipeline] sh
/var/jenkins_home/workspace/pruebaParametrizada@tmp/durable-71aead85/script.sh: 1: /var/jenkins_home/workspace/pruebaParametrizada@tmp/durable-71aead85/script.sh: Bad substitution
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Declarative: Post Actions)
[Pipeline] echo
Building finished successfully
I use to escape the quotes, nothing works.我用来转义引号,没有任何效果。 I get a bad substitution error.我得到一个错误的替换错误。 I've also tried without double quotes.我也试过没有双引号。
If I hardcode in the shell script arguments, it runs fine.如果我在 shell 脚本 arguments 中硬编码,它运行良好。
pipeline {
agent any
parameters {
string(defaultValue: "", description: '', name: 'One')
string(defaultValue: "", description: '', name: 'Two')
}
stages {
stage('Git Checkout') {
steps {
git credentialsId: 'personal-github', url: 'https:xxx'
}
}
stage('Maven Compile') {
steps {
sh 'mvn clean compile'
}
}
stage('Test One') {
steps {
//ERROR
sh 'mvn test -Dcucumber.options="-t @${params.One}"'
//This Works
//sh 'mvn test -Dcucumber.options="-t @One"'
}
}
}
post {
always {
echo 'Building finished successfully'
cucumber failedFeaturesNumber: -1,
failedScenariosNumber: -1,
failedStepsNumber: -1,
fileIncludePattern: '**/*.json',
jsonReportDirectory: 'target/cucumber/',
pendingStepsNumber: -1,
reportTitle: 'test features',
skippedStepsNumber: -1,
sortingMethod: 'ALPHABETICAL',
undefinedStepsNumber: -1
}
}
}
I found the way to pass parameters as follows`我找到了传递参数的方法如下`
sh """mvn test -Dcucumber.options='-t @${params.One}'"""
Thanks to all, for responses.感谢大家的回复。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.