0

So I have a groovy script like this-

def BRANCH_REV = sh script: "svn info \$url | grep 'Last Changed Rev' | awk '{ print \$4; }'", returnStdout: true , trim: true

println "ccsmp - downstream testing for: $BRANCH_REV"

This script is suppose to fetch the last revision number and put that value in a variable called "BRANCH_REV" and second line is suppose to print it. But I keep getting null value, my console output looks like this-

[branches%2Ffeatures%2Fcre40_jenkins] Running shell script
+ svn info
+ grep 'Last Changed Rev'
+ awk '{ print $4; }'
23401               <-- It is printing the revision number here

[Pipeline] echo
ccsmp - downstream testing for: 0      <-- but when I try to print the $BRANCH_REV, it prints out 0

[Pipeline] sh
[branches%2Ffeatures%2Fcre40_jenkins] Running shell script
+ echo 0
0                                    <-- same thing happens when I try to echo $BRANCH_REV
samkraken
  • 31
  • 1
  • 8

1 Answers1

0

Solution

If your script is in a Jenkinsfile and your pipeline is configured to checkout that Jenkinsfile ( IE the Jenkinsfile is stored with your code ) you can simply do the following:

def BRANCH_REV = "r${SVN_REVISION}"
echo "Revision is ${BRANCH_REV}"
Chris Maggiulli
  • 3,375
  • 26
  • 39