7

I am using Jenkins Pipeline for my .net project. I dont want to use the default build number so I am trying to set the build number using the following commands in groovy.

def short_hash = bat(script: 'git log --pretty=format:\'%%h\' -n 1', returnStdout: true)
currentBuild.displayName = '0.0.' + "${env.BUILD_NUMBER}" +'.' + short_hash

What I am observing is that short_hash is having the value of batch command along with the result.

The jenkins documentation here states that "script Executes a Batch script. Multiple lines allowed. When using the returnStdout flag, you probably wish to prefix this with @, lest the command itself be included in the output."

I tried using @ but it is giving error while executing it. Any pointers?

Gerhard
  • 22,678
  • 7
  • 27
  • 43
Tulika
  • 360
  • 5
  • 16

1 Answers1

1
def short_hash = bat(script: '@git log --pretty=format:\'%%h\' -n 1', returnStdout: true)
currentBuild.displayName = '0.0.' + "${env.BUILD_NUMBER}" +'.' + short_hash

put @ before git command