How to get svn version number from checkout for use in dsl

前端 未结 7 1859
南方客
南方客 2021-01-05 03:06

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

相关标签:
7条回答
  • 2021-01-05 03:30

    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}"
    
    0 讨论(0)
  • 2021-01-05 03:30

    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.

    0 讨论(0)
  • 2021-01-05 03:39

    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
    
    0 讨论(0)
  • 2021-01-05 03:40

    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.

    0 讨论(0)
  • 2021-01-05 03:42

    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

    0 讨论(0)
  • 2021-01-05 03:50

    Jenkins environment variable SVN_REVISION provides that straight away

    0 讨论(0)
提交回复
热议问题