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

"Calculate changelog against a specific branch" doesn't appear in configuration

      I have a typical Multibranch Pipeline using the GitHub branch source.

      I have a "main" branch. When people want to do a change they do it in a branch, which can later be merged into main. I use the discoverGitReferenceBuild step from the Git Forensics Plugin to specify all the other branches should use "main" as reference. But the "changes" list in the branch:

      • Is always empty in the first job
      • Is relative to the previous branch job for other jobs

      The git plugin has the "Calculate changelog against a specific branch" option (https://github.com/jenkinsci/git-plugin#calculate-changelog-against-a-specific-branch). But I can't set it from the Multibranch Pipeline project configuration, it's just not there in the list of options.

      You could say this is a github-branch-source plugin issue. But the option doesn't appear if I use just "git" as a branch source either (it's there if I use "Single repository & branch"), so I suspect the issue is in the git plugin.

       

      This basic workflow can actually be supported, but it's strangely complicated to. I have had to:

      • Explicitly specify the main branch in "Specify ref specs", since otherwise the clone didn't have the branch to "Calculate against".
      • Change a simple (possibly implicit) 
        checkout scm

        for 

        def get_gitscm_extensions_list() {
          if(env.BRANCH_NAME == 'main') {
            return scm.extensions
          }
        
          return scm.extensions + [changelogToBranch(changelogBase(compareRemote: 'origin', compareTarget: 'main'))]
        }
        
        ....
        
        checkout scmGit(branches: scm.branches, extensions: get_gitscm_extensions_list(), userRemoteConfigs: scm.userRemoteConfigs)

      Specifically, the lack of the change list in the first job of a branch, which people want to use for example to find the user to send notifications to or to decide whether the job should be built makes people unable to find the above solution do weird things. See, for example, the explanation about the "currentBuild.previousCompletedBuild != null" trick in https://stackoverflow.com/questions/60084946/jenkins-git-changelog-on-first-build

       

      I am also wondering why I do even need a discoverGitReferenceBuild step. I really want the change list to match the reference build, so it would make sense for both things to be calculated by the same plugin. Shouldn't the git plugin set the reference build when it finds it when looking for it to create the changes list?

          [JENKINS-72056] "Calculate changelog against a specific branch" doesn't appear in configuration

          Mark Waite added a comment -

          Shouldn't the git plugin set the reference build when it finds it when looking for it to create the changes list?

          The git plugin can't reliably calculate the reference build from the information available to it. The git plugin limits itself to command line git operations and JGit operations. Command line git does not have a concept of a "base branch" or a "pull request" or a "merge request". Those are concepts provided by higher level SCM systems like GitHub, Bitbucket, GitLab, Gitea, Assembla, and Tulip.

          Mark Waite added a comment - Shouldn't the git plugin set the reference build when it finds it when looking for it to create the changes list? The git plugin can't reliably calculate the reference build from the information available to it. The git plugin limits itself to command line git operations and JGit operations. Command line git does not have a concept of a "base branch" or a "pull request" or a "merge request". Those are concepts provided by higher level SCM systems like GitHub, Bitbucket, GitLab, Gitea, Assembla, and Tulip.

          Cristian added a comment - - edited

          Those are concepts provided by higher level SCM systems like GitHub, Bitbucket, GitLab, Gitea, Assembla, and Tulip.

          Or by the user.

          Aren't "discoverGitReferenceBuild" and "checkout"/"scmGit" with changelogToBranch doing the same thing?

          It's building branch A, and the users gives

          • discoverGitReferenceBuild a "targetBranch"
          • checkout a "compareTarget"

          Then I guess they use https://git-scm.com/docs/git-merge-base to find the common commit between A and targetBranch/compareTarget? (discoverGitReferenceBuild then, additionally, find the Jenkins job that built that commit).

           

          In any case, people should be able to set "Calculate changelog against a specific branch" from the configuration of a Multibranch Pipeline git branch source, no?

          Cristian added a comment - - edited Those are concepts provided by higher level SCM systems like GitHub, Bitbucket, GitLab, Gitea, Assembla, and Tulip. Or by the user. Aren't "discoverGitReferenceBuild" and "checkout"/"scmGit" with changelogToBranch doing the same thing? It's building branch A, and the users gives discoverGitReferenceBuild a "targetBranch" checkout a "compareTarget" Then I guess they use https://git-scm.com/docs/git-merge-base to find the common commit between A and targetBranch/compareTarget? (discoverGitReferenceBuild then, additionally, find the Jenkins job that built that commit).   In any case, people should be able to set "Calculate changelog against a specific branch" from the configuration of a Multibranch Pipeline git branch source, no?

            Unassigned Unassigned
            reddwarf94 Cristian
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: