Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-66479

Reference build discovery doesn't work if added to old existing projects

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Major Major
    • git-forensics-plugin
    • None

      Because of the way the find reference build loop is written, it fails to find a reference build if the git forensics is added  to a project (for example, converting a legacy project to a pipeline) if there are enough commits in repository, even if an appropriate reference build is the HEAD of the reference branch.

      The culprit is the getReferencePoint function, because the loop starts with the commit list initialized to the reference job's latest commits - which will be all of them on the first build, and if there are enough the loop won't even run once.

      Reproduce steps:

      • Create a new git repository
      • Add a Jenkinsfile script that checks out the branch (checkout scm), and uses discoverGitReferenceBuild
      • Add over 100 commits to the repository
      • Create a new branch off the HEAD
      • Create a new multibranch pipeline job in Jenkins for the repository
      • Build the mainline
      • Build the branch

      I have created a repository https://github.com/Cetlan/git-forensics-bug that takes care of the first four steps.

      The logs for the branch build should indicate that no reference build was found, even though the appropriate reference build should be the only build and the common commit should be the most recent commit in that branch)

      "Workaround":

      Set maxCommits to at least the number of commits in the longest branch that could be needed for a reference branch, at least until all branches/PRs are based on commits that are in "smaller" builds.

          [JENKINS-66479] Reference build discovery doesn't work if added to old existing projects

          Christopher added a comment -

          I had a further thought about this, this bug should actually cause the reference build detection to fail repeatedly, it's not just when adding to an existing large repository, but multibranch pipelines will be a problem.

          Unless I didn't quite follow the implementation, when a new branch is created, that branch will be a new job in Jenkins, and the job's first build will contain the full commit history. Which means that commits that had reference builds in the parent branch's job might not be found in the new branch, because the first build could have too much history. I can see this causing a problem (especially for code coverage comparisons) if dealing with "nested" branching (for example break a feature branch off the trunk, and a subfeature branch off that for some reason) as reference build detection might not work properly between the subfeature and feature.

          Since I don't think now that this problem is limited to only when git-forensics is added to an existing, large repo, I'm upgrading this to a "major" bug.

          Christopher added a comment - I had a further thought about this, this bug should actually cause the reference build detection to fail repeatedly, it's not just when adding to an existing large repository, but multibranch pipelines will be a problem. Unless I didn't quite follow the implementation, when a new branch is created, that branch will be a new job in Jenkins, and the job's first build will contain the full commit history. Which means that commits that had reference builds in the parent branch's job might not be found in the new branch, because the first build could have too much history. I can see this causing a problem (especially for code coverage comparisons) if dealing with "nested" branching (for example break a feature branch off the trunk, and a subfeature branch off that for some reason) as reference build detection might not work properly between the subfeature and feature. Since I don't think now that this problem is limited to only when git-forensics is added to an existing, large repo, I'm upgrading this to a "major" bug.

          Ulli Hafner added a comment -

          I think this can be fixed by enabling the property latestBuildIfNotFound.

          Ulli Hafner added a comment - I think this can be fixed by enabling the property latestBuildIfNotFound .

            drulli Ulli Hafner
            cetlan Christopher
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: