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

No new commits used if LocalBranch checked in same workspace

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Minor Minor
    • git-plugin
    • None
    • Any version from

      Reproduce steps:

      • Create branch
      • Execute pipeline with LocalBranch
      • Add commits to branch
      • Repeat pipeline in same workspace - no new commits will be used from original

      Criteria to reproduce:

      • Usage of LocalBranch extension
      • Usage of original branch name containig '/' symbol

      Problem in class:

      hudson.plugins.git.util.DefaultBuildChooser#getCandidateRevisions
      

      Example Pipeline:

      node('master') {
          stage('Checkout'){
              script {
                  String url = 'https://example.com/repository.git'
                  //: Branch name containing `/` symbol
                  String branch = 'feature/branch'
                  String credentialsId = 'secret-credentials'
      
                  //: Checkout original
                  checkout scm: [
                      $class: 'GitSCM',
                      userRemoteConfigs: [
                          [
                              url: url,
                              credentialsId: credentialsId
                          ]
                      ],
                      extensions: [[$class: 'LocalBranch']],
                      branches: [
                          [name: branch]
                      ]
                  ]
      
                  //: Change local history
                  sh('git reset --hard HEAD^')
      
                  //: Checkout one more time - local history will be used
                  checkout scm: [
                      $class: 'GitSCM',
                      userRemoteConfigs: [
                          [
                              url: url,
                              credentialsId: credentialsId
                          ]
                      ],
                      extensions: [[$class: 'LocalBranch']],
                      branches: [
                          [name: branch]
                      ]
                  ]
      
              }
          }
      }
      

      Workaround:

      Execute before checkout

      sh('rm -rf .git/refs/heads/*')
      

      To remove local branches refs

            Unassigned Unassigned
            xxxbobrxxx vladislav piskunov
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: