简体   繁体   中英

Using global variables to push tags to Git in Jenkins Pipeline

I cannot wrap my head around using global variables in Git commands. I have the following code:

stage('Publish to GIT') {
    steps {
        bat 'git push -v origin website-0.${env.BUILD_NUMBER}'
    }
}

BUILD_NUMBER is a global variable used in Jenkins but I cannot get it to resolve. I also tried using Powershell but to no avail. I also tried ${BUILD_NUMBER} $BUILD_NUMBER but without success.

Any ideas what I am doing wrong? Thanks in advance!

Regards

when you are using pipelines be notted that it is groovy , which means you have to follow code/syntax rulles. in your snippet the only mistake is that you are using ' in stead of " which means follwing: usage of ' - whatever is inside is treated as String, so ${env.BUILD_NUMBER} wont be executed usage of " - whatever is inside is teated as String, apart from ${SOMETHING} which will be executed and changed with the value of the var

having that in mind you have to have following instead what you have now:

stage('Publish to GIT') {
    steps {
        sh|bat "git push -v origin website-0.${env.BUILD_NUMBER}"
    }
}

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