简体   繁体   中英

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

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?

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}"}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM