0

We are using below command to find out the last commit to the git

{ git log -1 --pretty=format:'%an'; echo "@xyzcompany.com, developer@xyzcompany.com"; } | xargs -I{} echo {} | sed 's/\n//' 

Note: this command is working in CLI in jenkins workspace project.

How to inject this command in jenkins pipeline script??

tostao
  • 2,803
  • 4
  • 38
  • 61
Nithin
  • 13
  • 1
  • 9
  • You might want to have a look into this answer to simplify your command: https://stackoverflow.com/a/19176626/437621 – Michael Oct 09 '18 at 04:51

1 Answers1

0

You can just use an sh to execute the command. If you are using declarative syntax (starting with pipeline instead of node) I'd suggest to do that in the environment, so you can read the result in all stages of your pipeline:

environment {
    COMMIT = sh(script: '{ git log -1 --pretty=format:\'%an\'; echo "@xyzcompany.com, developer@xyzcompany.com"; } | xargs -I{} echo {} | sed \'s/\n//\'', returnStdout: true).trim()
}

Or –if you use scripted syntax– you just declare a variable:

def commit = sh(script: '{ git log -1 --pretty=format:\'%an\'; echo "@xyzcompany.com, developer@xyzcompany.com"; } | xargs -I{} echo {} | sed \'s/\n//\'', returnStdout: true).trim()
Michael
  • 2,443
  • 1
  • 21
  • 21