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

荒凉一梦 提交于 2019-12-13 16:20:30

问题


I have stage in my jenkinsfile, that executes a bat command:

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

My batch command requires a parameter that is the current branch in svn.

When I use this:

echo "SVN_BRANCH_NAME is ${env.BRANCH_NAME}"

It would give the value of BRANCH_NAME but if I pass it as param to my batch file, it literally pass ${env.BRANCH_NAME} not the value.

Is their a way to do this?


回答1:


It's because all is wrapped in single quotes and groovy won't interpolate the string. Try

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


来源:https://stackoverflow.com/questions/52446523/how-to-use-groovy-env-variable-in-jenkins-to-pass-through-bat-command-in-jenkin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!