Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get SVN revision in declarative jenkins pipeline

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.

like image 431
Marcel M. Avatar asked May 15 '18 08:05

Marcel M.


2 Answers

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
}
like image 81
Marcel M. Avatar answered Nov 14 '22 16:11

Marcel M.


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.

like image 35
BigGinDaHouse Avatar answered Nov 14 '22 16:11

BigGinDaHouse