-1

I have the following IF condition in my groovy script:

if (git log -1 --pretty=format:'%an' == 'xyz')

Here all i am trying to achieve is that i need to have the value of

git log -1 --pretty=format:'%an'

equate to some string lets say here xyz I can easily do that in shell as below

if [ `git log -1 --pretty=format:'%an'` == "xyz" ]

But unable to get that to work in my groovy IF

James Z
  • 12,209
  • 10
  • 24
  • 44
Ashley
  • 1,447
  • 3
  • 26
  • 52

1 Answers1

1

If you use it in Jenkinsfile

def log = sh(returnStdout: true, script: "git log -1 --pretty=format:'%an'").trim()
if (log == 'xyz') {
  ...
}

If you use it in pure Groovy (below solution also work in Jenkinfile)

def log = "git log -1 --pretty=format:'%an'".execute().text
if (log == 'xyz') {
  ...
}

yong
  • 13,357
  • 1
  • 16
  • 27