Jenkins – How to get the git latest commit message in jenkins and apply regular expressions on it to find needed data

Jenkinsjenkins-plugins

i need to build a job in Jenkins, to get latest git commit message every time a commit is done and to store it in a variable.Can anyone suggest a plugin or a way to do this?

Best Answer

Use command line and get the commit message that you want and create a file as key value and inject the variable:

Step by step:

  1. Install git plugin, EnvInject Plugin.

  2. Get the last git commit by the command git log -p -1 and parse from that what you need.

  3. Create a file as key value for example LAST_COMMIT_ID=cab123gfbdak

  4. Use the envInject as file (this load the key value file that you created to Jenkins as Jenkins variable).

Good luck.