Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changes not detected in pull requests on Jenkins pipeline plugin

I have Jenkins configured to build on pull requests (PR). Our repository is a multi project repository and I have created a script to detect the changes that were made to source code and only run tests that are relevant to the projects that had changes in them (according to the changed file's path):

def getChangedProjects() {
  Set projects = []
  def changeLogSets = currentBuild.changeSets
  for (int i = 0; i < changeLogSets.size(); i++) {
      def entries = changeLogSets[i].items
      for (int j = 0; j < entries.length; j++) {
          def entry = entries[j]
          def files = new ArrayList(entry.affectedFiles)
          for (int k = 0; k < files.size(); k++) {
            def file = files[k]
            // get the project folder name and
            // add it to changed projects set
            projects.add(file.path.tokenize('/')[1])
          }
      }
  }
  return projects.findAll {it != null}
}

The Groovy function works as expected and detects the folder that has changed.

Problem is that most of the times Jenkins will not show any changes in Jenkins:

Changes are not shown

But the PR did contain changes to files and I can see these changes in Github of course.

Anyone know why Jenkins is not showing the changes ?

like image 311
Michael Avatar asked Nov 29 '18 10:11

Michael


1 Answers

You may create a change log by including a Git Changelog step in the Jenkins pipeline script.

This plugin provides a context object that contains all the information needed to create a changelog. It can also provide a string that is a rendered changelog, ready to be published.

Here is a screenshot of a sample Git changelog produced by this plugin:

Git Changelog


More information about this plugin may be found in its wiki.

Hope, it helps.

like image 105
Sanjeev Sachdev Avatar answered Sep 20 '22 07:09

Sanjeev Sachdev