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

JobDSL BbS method generates incorrect XML structure for Bitbucket Server Integration plugin 4.0+, causing extensions to be ignored

XMLWordPrintable

      Problem Summary

      The JobDSL plugin's BbS method generates XML that is incompatible with Bitbucket Server Integration plugin versions 4.0 and later. Extensions defined in JobDSL are not applied in the Jenkins UI and do not function, despite being present in the generated XML.

      Root Cause

      The Bitbucket Server Integration plugin changed its XML structure in version 4.0+ to require:

      1. Extensions defined within a nested <gitSCM> block
      1. Extension references in the main <extensions> block using XML references

      However, JobDSL's BbS method still generates the old XML structure where extensions are placed directly under the main <scm> node.

      Below is the extension, that ones worked.

       

      mavenJob('test-job') {
       scm {
              BbS {            
                  id('if-branches')  
                  branches {
                      branchSpec { name('**/feature/*') }
                      branchSpec { name('**/bugfix/*') }
                  }
                  gitTool('')  
                  credentialsId('bitb-cred-id')
                  sshCredentialsId('')   
                  projectName('some')
                  repositoryName('one')
                  serverId('bitbucket-id')
                  mirrorName('')  
                  extensions {
                      buildChooserSetting {
                          buildChooser {
                              ancestryBuildChooser {
                              maximumAgeInDays(1)
                              ancestorCommitSha1('')
                              }                       
                          }
                      }
                      cloneOption {
                          shallow(true)
                          depth(1)
                          noTags(true)
                          reference('')
                          honorRefspec(true)
                          timeout(10) 
                      }
                  }
              }
          } 
      }

       

       

      Current Behavior (Incorrect)

      JobDSL generates:

      <scm class="com.atlassian.bitbucket.jenkins.internal.scm.BitbucketSCM">      <extensions>
          <hudson.plugins.git.extensions.impl.CloneOption>  
            <shallow>true</shallow>
            <noTags>true</noTags>  
            <depth>1</depth>  
          </hudson.plugins.git.extensions.impl.CloneOption> 
       </extensions>
      </scm> 

      Expected Behavior (Correct)

      Should generate:

       

      <scm class="com.atlassian.bitbucket.jenkins.internal.scm.BitbucketSCM"> 
       <gitSCM plugin="git@5.7.0">  
        <extensions>    
        <hudson.plugins.git.extensions.impl.CloneOption>
          <shallow>true</shallow>     
          <noTags>true</noTags>     
          <depth>1</depth>    
        </hudson.plugins.git.extensions.impl.CloneOption> 
         </extensions>  
      </gitSCM> 
       <extensions>  
        <hudson.plugins.git.extensions.impl.CloneOption reference="../../gitSCM/extensions/hudson.plugins.git.extensions.impl.CloneOption"/> 
       </extensions>
      </scm> 

       

      Impact

      • All Git extensions (cloneOption, buildChooserSetting, etc.) are ignored by the Bitbucket plugin
      • Jobs don't perform shallow clones, build selection, path restrictions, etc. as configured
      • Affects organization-wide CI/CD pipelines using JobDSL with Bitbucket Server

      Workaround

      Currently requires using configure blocks to manually generate correct XML:

      configure { project ->   
          def scmNode = project / 'scm'
          scmNode / 'gitSCM'(plugin: 'git@5.7.0') {
              extensions {
                  'hudson.plugins.git.extensions.impl.CloneOption' {
                          shallow('true')
                          depth('1') 
                          noTags('true') 
                        }
                    }
                } 
         scmNode / 'extensions' {
              'hudson.plugins.git.extensions.impl.CloneOption'(reference: '../../gitSCM/extensions/hudson.plugins.git.extensions.impl.CloneOption')
            }
         }

      Suggested Fix

      Update the JobDSL plugin's Bitbucket SCM handler to generate the new XML structure required by Bitbucket Server Integration plugin 4.0+. The fix should:

      1. Create nested gitSCM block with extensions
      1. Add extension references in main extensions block
      1. Maintain backward compatibility with older plugin versions if possible

       

       

            jamietanna Jamie Tanna
            halli_blondal Haraldur
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: