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

Jenkins only displays commit but not the branch name

      I want to retrieve the code branch name during Java packaging. I am using the git-commit-id-plugin. In the git.properties file generated when running on my local computer, the value of git.branch is the branch name. However, in the git.properties file generated during packaging on the Jenkins environment server, the value of git.branch is the commit ID. 

      Here jenkins checks out the code in detached head mode.

      Note:- We had reached out to manitainer for this plugin and he asked to get fix from jenkins, Please find the link below for your refernce.

      https://github.com/git-commit-id/git-commit-id-maven-plugin/issues/325

          [JENKINS-73216] Jenkins only displays commit but not the branch name

          Mark Waite added a comment -

          For historic compatibility reasons, the Jenkins git plugin creates a "detached head" checkout rather than performing a checkout to a specific branch. It is surprising to many users, but we cannot change the default behavior without breaking many users that depend on the default behavior.

          "Checkout to specific local branch" is an option that you can add to git checkout in Jenkins Pipeline, Jenkins freestyle, and other Jenkins jobs that use the git plugin. When that option is enabled, then the checkout will create a local branch with the specified name.

          Mark Waite added a comment - For historic compatibility reasons, the Jenkins git plugin creates a "detached head" checkout rather than performing a checkout to a specific branch. It is surprising to many users, but we cannot change the default behavior without breaking many users that depend on the default behavior. "Checkout to specific local branch" is an option that you can add to git checkout in Jenkins Pipeline, Jenkins freestyle, and other Jenkins jobs that use the git plugin. When that option is enabled, then the checkout will create a local branch with the specified name.

          Pasupula added a comment -

          We encountered this issue after upgrading Jenkins from version 2.289.3 to 2.426.3. Following the upgrade, the git branch attribute for the git-commit-id Maven plugin is not functioning correctly. We contacted the maintainer of the plugin, who suggested checking Jenkins for a fix. You can see the maintainer's comments on issue #325 via the link below.

          Pasupula added a comment - We encountered this issue after upgrading Jenkins from version 2.289.3 to 2.426.3. Following the upgrade, the git branch attribute for the git-commit-id Maven plugin is not functioning correctly. We contacted the maintainer of the plugin, who suggested checking Jenkins for a fix. You can see the maintainer's comments on issue #325 via the link below.

          Mark Waite added a comment -

          Adding the "checkout to specific local branch" option to your Pipeline checkout command is the expected way to resolve the issue. The Jenkins git plugin will not change its default of using a detached head checkout because that risks breaking compatibility for many, many users.

          I don't know why you didn't see the same problem with Jenkins 2.289.3, since it has been the behavior as long as I've maintained the Jenkins git plugin. It might be that you had a long-lived agent workspace that was checked out at one point with a named branch and then was continually reused.

          While I appreciate that the maintainer of the git-commit-id Maven plugin thinks that Jenkins should change its default checkout, I'm unwilling to do so. I won't risk incompatibility for many, many users.

          Mark Waite added a comment - Adding the "checkout to specific local branch" option to your Pipeline checkout command is the expected way to resolve the issue. The Jenkins git plugin will not change its default of using a detached head checkout because that risks breaking compatibility for many, many users. I don't know why you didn't see the same problem with Jenkins 2.289.3, since it has been the behavior as long as I've maintained the Jenkins git plugin. It might be that you had a long-lived agent workspace that was checked out at one point with a named branch and then was continually reused. While I appreciate that the maintainer of the git-commit-id Maven plugin thinks that Jenkins should change its default checkout, I'm unwilling to do so. I won't risk incompatibility for many, many users.

          Pasupula added a comment -

          markewaite , Thanks for your response. Here We are following a multibranch pipeline. What I want to convey is that whenever a new branch is created in Git, it will appear in Jenkins to trigger the job to build the code for that particular branch. Each new branch will create a new workspace, and we are not using the same workspace for all branches

          Pasupula added a comment - markewaite , Thanks for your response. Here We are following a multibranch pipeline. What I want to convey is that whenever a new branch is created in Git, it will appear in Jenkins to trigger the job to build the code for that particular branch. Each new branch will create a new workspace, and we are not using the same workspace for all branches

            markewaite Mark Waite
            venky2291 Pasupula
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: