[英]Using Jenkins job parameter in a bat command
I'm trying to configure a parameter in Jenkins pipeline and then execute it within bat command:我正在尝试在 Jenkins 管道中配置一个参数,然后在 bat 命令中执行它:
pipeline {
agent {
label 'master'
}
parameters {
string (
defaultValue: '"someExe.exe"',
description: '',
name : 'varExe'
)
}
stages {
stage("hi") {
steps {
script {
bat '${params.varExe}'
}
}
}
}
}
Unfortunately, i'm getting this error:不幸的是,我收到了这个错误:
'${varExe}'is not recognized as an internal or external command
For some reason, Jenkins doesn't use varExe
value.出于某种原因,Jenkins 不使用varExe
值。
I've also tried bat '${varExe}'
but still no luck.我也试过bat '${varExe}'
但仍然没有运气。
Any ideas?有任何想法吗?
You need to use a double quote here to replace the variable. 您需要在此处使用双引号替换变量。
bat "${params.varExe}"
You have to be careful with single and double quotes. 您必须小心单引号和双引号。 For the following example, the first one would echo someExe.exe, while the second one would throw a Bad substitution error. 对于以下示例,第一个将回显someExe.exe,而第二个将引发Bad替换错误。
pipeline {
agent any
parameters {
string (
defaultValue: '"someExe.exe"',
description: '',
name : 'varExe')
}
stages {
stage ('Test') {
steps {
script {
sh "echo '${params.varExe}'"
sh 'echo "${params.varExe}"'
}
}
}
}
}
I think for bat command should be like below我认为 bat 命令应该如下所示
bat ''' echo %varExe% '''
reference: pass parameter from jenkins parameterized build to windows batch command参考: 将参数从 jenkins 参数化构建传递到 windows 批处理命令
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.