6

I have a simple question: How can I get the svn revision in a declarative jenkins pipeline. Similar to this post.

What I found out so far:

When you use a Freestyle job, simply use

${SVN_REVISION}

When you use a Scripted Pipeline, use the following command:

def scmVars = checkout([$class: 'SubversionSCM',...])
svnRevision = scmVars.SVN_REVISION

checkout syntax

But how do I get the SVN Revision in a Declarative Pipeline? SVN_REVISION is not defined, def is not allowed in declarative pipelines and checkout scm is only for multibranch pipelines.

Marcel M.
  • 111
  • 1
  • 7

2 Answers2

3

Thanks for the quick answer. I found another solution with script. I know it is not the best solution, but it works.

script {
    def scmVars = checkout ([$class: 'SubversionSCM',...])
    svnRevision = scmVars.SVN_REVISION
}
Marcel M.
  • 111
  • 1
  • 7
2

according to here https://qa.nuxeo.org/jenkins/pipeline-syntax/globals

The following variables are currently unavailable inside a Pipeline script:

SCM-specific variables such as SVN_REVISION

so better try to find the way (the best one will be shell script) to get revision after checking out and then use it for your needs.

BigGinDaHouse
  • 1,282
  • 9
  • 19