I created a pipeline job and would like to get the svn version number to enable further downstream processing in a call to a shell script. I am using a pipeline script simi
this code work for me in jenkins pipeline:
String url = 'svn+ssh:...'
SVN_REVISION_IN = sh returnStdout: true, script: 'svn info --show-item last-changed-revision ' + url
currentBuild.displayName = "Rev: ${SVN_REVISION_IN}"
There is a file called revision.txt in the build dir. The SubversionSCM provides methods to read this file.
//Here remote returns url@revision but the revision part is across the entire repo
//We will use the url part to get the revision for our branch
def remote = scm.locations.first().remote
def url = remote.split('@').first()
//The revision file has the revision for our branch. Parse returns a map.
def revmap = scm.parseRevisionFile(currentBuild.rawBuild)
revmap[url]
The scm variable is available on Jenkinsfiles. If you are not using a Jenkinsfile you should be able to create the scm object and pass it into the checkout method.
I had the same issue, but you can solve it by using the map that is returned from calling SCM checkout. It contains a value for SVN_REVISION.
// Get some code from a SVM repository
def scmVars = checkout(
...
)
def svnversionnumber = scmVars.SVN_REVISION
I ended up invoking a shell to get the svn revision number as follows
def svnVersionNumber = sh(
script: "svn info --show-item last-changed-revision $url",
returnStdout: true
)
This was the only way I could get it to work correctly.
I think one of the best choice can be use a simple little "groovy console script" to get the revision number then put into a Jenkins variable..
Something like this to give you an idea: Link
Take also a look at this question: Link
Jenkins environment variable SVN_REVISION provides that straight away