I have the following Jenkinfile content that is able to create the tag name as I want and stored in the varibale 'tag'. How can I use that variable in a batch command here?
Note that Jenkins is on a Windows machine thus using bat command. Am all ears if there is a simple way I could switch to bash. But the main question is as follows. Thank you.
How can I use that 'tag' variable (which has correct value stored before I try to use it in a batch command)? Currently it is coming out with no value with my implementation below trying to echo it.
#!/usr/bin/groovy
pipeline{
agent any
stages {
stage('tag stage'){
steps {
gitTag()
}
}
}
}
def gitTag(){
String date = new Date().format('yyyyMMddhhmmss')
String branch = "${env.GIT_BRANCH}"
String tag = "v${date}-${branch}"
tag = tag.replaceAll('/', '-')
String message = "tagged via jenkins - ${tag}"
print message
bat 'echo Hello test'
bat 'echo from bat before tag %tag% after tag'
bat 'git tag -a %tag% -m "tagging with %message%"'
bat 'git push origin %tag%'
}