在bat命令中使用Jenkins job参数 [英] Using Jenkins job parameter in a bat command
本文介绍了在bat命令中使用Jenkins job参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在Jenkins管道中配置参数,然后在bat命令中执行它:
I'm trying to configure a parameter in Jenkins pipeline and then execute it within bat command:
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
由于某些原因,詹金斯不使用varExe
值.
For some reason, Jenkins doesn't use varExe
value.
我也尝试过bat '${varExe}'
,但还是没有运气.
I've also tried bat '${varExe}'
but still no luck.
有什么想法吗?
推荐答案
您需要在此处使用双引号替换变量.
You need to use a double quote here to replace the variable.
bat "${params.varExe}"
您必须小心单引号和双引号.对于下面的示例,第一个将回显someExe.exe,而第二个将引发错误的替换错误.
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.
pipeline {
agent any
parameters {
string (
defaultValue: '"someExe.exe"',
description: '',
name : 'varExe')
}
stages {
stage ('Test') {
steps {
script {
sh "echo '${params.varExe}'"
sh 'echo "${params.varExe}"'
}
}
}
}
}
这篇关于在bat命令中使用Jenkins job参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文