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.
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
}
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With