将参数传递给 Jenkins 中的 shell 脚本时替换错误
Bad substitution when passing parameter to shell script in Jenkins
我试图通过设置 shell 脚本的 stdOut 来传递变量的值。
但是在 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
我用来转义引号,但没有用。我得到一个错误的替换错误。我也试过没有双引号。
如果我在 shell 脚本参数中进行硬编码,它运行良好。
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
}
}
}
找到如下传参方式`
sh """mvn test -Dcucumber.options='-t @${params.One}'"""
感谢大家的回复。
我试图通过设置 shell 脚本的 stdOut 来传递变量的值。 但是在 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
我用来转义引号,但没有用。我得到一个错误的替换错误。我也试过没有双引号。
如果我在 shell 脚本参数中进行硬编码,它运行良好。
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
}
}
}
找到如下传参方式`
sh """mvn test -Dcucumber.options='-t @${params.One}'"""
感谢大家的回复。