如何使用 groovy 环境。 Jenkins 中的变量通过 Jenkins 管道中的 bat 命令

How to use groovy env. variable in Jenkins to pass through bat command in Jenkins pipeline

我的 jenkinsfile 中有一个执行 bat 命令的阶段:

stage ('build'){
  bat '%cd%\MySimpleProject\bin\Execute.bat "${env.BRANCH_NAME}"'
}

我的批处理命令需要一个参数,它是 svn 中的当前分支。

当我使用这个时:

回声"SVN_BRANCH_NAME is ${env.BRANCH_NAME}"

它会给出 BRANCH_NAME 的值,但如果我将它作为参数传递给我的批处理文件,它实际上会传递 ${env.BRANCH_NAME} 而不是值。

他们有办法做到这一点吗?

这是因为所有内容都用单引号引起来,groovy不会插入字符串。尝试

stage ('build'){ bat "%cd%\MySimpleProject\bin\Execute.bat ${env.BRANCH_NAME}"}