jenkinsjenkins-plugins

What commits are pulled by Jenkins in the build?


Jenkins has information about commits included in a particular build. I know this because Jenkins displays this (see the screenshot below).

How can I pull the information about commits included in the build during the CI execution?

This information is required to check what folders have files modified and, as a result, to determine what actions Jenkins should execute.

P.S. To achieve this in CI jobs for PRs, I use git command:

git rev-parse github/master

It returns the last commit made in master before current branch was branched off (to make it work I add 'github' remote). Obviously, it can't work in the 'master' branch itself. So I'm thinking, maybe Jenkins has some built-in information that I can use? Or some Jenkins plugins can help?

enter image description here


Solution

  • Apparently, there is a bunch of links, though I could not find any until I figured the keyword to google for it.

    1st of all, there is a DevOps version of StackOverflow: https://devops.stackexchange.com/ It might have more people active that can help with Jenkins related questions

    2nd, the idea is to use jenkins variable currentBuild and further iterated through:

    Links that helped me to figure out the solution:

    IMPORTANT NOTES:

    1. Because of how Groovy works in Jenkins you need to put this logic into a separate function and add "@NonCPS" attribute to it
    2. All variables inside need to be prefixed by 'def' (even though my prettier told me this is not required), without this you will have "java.io.NotSerializableException: hudson.plugins.git.GitChangeSetList" errors.

    Hope this will help someone as well!