This is already available for Pipeline jobs by using the {{GIT_COMMIT}} (sha1 of the commit) value returned in the map of the {{checkout}} step. Use that SHA1 to call a shell step and read the commit message into your Pipeline. {noformat} branch = 'JENKINS-50401' checkout_result = checkout([$class: 'GitSCM', branches: [[name: branch]], extensions: [[$class: 'CloneOption', honorRefspec: true, noTags: true], [$class: 'LocalBranch', localBranch: branch] ], userRemoteConfigs: [[refspec: "+refs/heads/${branch}:refs/remotes/origin/${branch}", url: 'https://github.com/MarkEWaite/jenkins-bugs.git']]]) commit_message = sh returnStdout: true, script: "git log -n 1 ${checkout_result.GIT_COMMIT)" {noformat}
If that same information is needed in a Freestyle project, you'll need to use a similar technique from within the build script. |
|