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

GIT_LOCAL_BRANCH var is not setting when we enabled for "check out to matching local branch" via declarative pipeline

    • Icon: Bug Bug
    • Resolution: Not A Defect
    • Icon: Major Major
    • None
    • Jenkins 2.440.3

      When we enabled "Check out to matching local branch" in the Jenkins UI, it worked fine, and we could see that the "GIT_LOCAL_BRANCH" variable was getting the appropriate branch value. However, when we tried to enable it in the code using a declarative pipeline, we did not see the "GIT_LOCAL_BRANCH" variable. Below is the snippet of code we are using. Could you please have a look and help me out with this?

       

      Code Snippet:-

      checkout([
      $class: 'GitSCM',
      branches: scm.branches, // Jenkins job should add "Discover branches" and "Discover tags" to "Behaviors" subsection within the "Branch Sources" section
      extensions: [
      pruneTags(true), // Prune stale tags
      [$class: 'CloneOption', noTags: false], // Fetch tags
      [$class: 'LocalBranch', localBranch: "**"], // evaluate branch name
      [$class: 'PruneStaleBranch'], // Prune stale branches
      [$class: 'WipeWorkspace'] // Wipe out the workspace before cloning to ensure it is clean
      ],
      userRemoteConfigs: scm.userRemoteConfigs
      ])

       

       

          [JENKINS-73229] GIT_LOCAL_BRANCH var is not setting when we enabled for "check out to matching local branch" via declarative pipeline

          Mark Waite added a comment - - edited

          Please don't use the Jenkins issue tracker for question and answer.

          There are many more people that are willing and able to answer questions in the Jenkins community forum, the Jenkins user mailing list, and the Jenkins chat channels. A much smaller group of people review the Jenkins issue tracker because we use it for bugs and enhancement requests, not for question and answer.

          I created a sample job in a multibranch Pipeline repository that I use for many other branches and many other tests. I confirmed that when localBranch('**') is added as an extension, a branch with the expected name is created in the workspace.

          Mark Waite added a comment - - edited Please don't use the Jenkins issue tracker for question and answer. There are many more people that are willing and able to answer questions in the Jenkins community forum, the Jenkins user mailing list, and the Jenkins chat channels. A much smaller group of people review the Jenkins issue tracker because we use it for bugs and enhancement requests, not for question and answer. I created a sample job in a multibranch Pipeline repository that I use for many other branches and many other tests. I confirmed that when localBranch('**') is added as an extension, a branch with the expected name is created in the workspace.

            Unassigned Unassigned
            venky2291 Pasupula
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: