Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save vonschnappi/804ab70bddd82fd163998392c61effb1 to your computer and use it in GitHub Desktop.
Save vonschnappi/804ab70bddd82fd163998392c61effb1 to your computer and use it in GitHub Desktop.
Getting the commit message when running a Jenkins pipeline job
commit = sh(returnStdout: true, script: 'git log -1 --oneline').trim()
String commitMsg = ""
List commitMsgPre = commit.split(" ")
for(int i=1; i<commitMsgPre.size(); i++){
commitMsg += commitMsgPre.getAt(i) + " "
}
@twalker
Copy link

twalker commented May 19, 2021

git log -1 --oneline

@twalker
Copy link

twalker commented May 19, 2021

(git log -1 --pretty=%B)

@gerib
Copy link

gerib commented Aug 5, 2021

Many thanks for this snippet! But everything after

commit = ...

can be replaced by the one line

commitMsg = commit.substring( commit.indexOf(' ') ).trim()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment