Skip to content

[JENKINS-75792] JobDSL BbS method generates incorrect XML structure for Bitbucket Server Integration plugin 4.0+, causing extensions to be ignored #2532

@jenkins-infra-bot

Description

@jenkins-infra-bot

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:

Extensions defined within a nested <gitSCM> block
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="[email protected]">  
  <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: '[email protected]') {
        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:

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


Originally reported by halli_blondal, imported from: JobDSL BbS method generates incorrect XML structure for Bitbucket Server Integration plugin 4.0+, causing extensions to be ignored
  • assignee: jamietanna
  • status: Open
  • priority: Major
  • component(s): atlassian-bitbucket-server-integration-plugin, job-dsl-plugin
  • label(s): XML, bitbucket-server, extension, regression, scm, triaged
  • resolution: Unresolved
  • votes: 0
  • watchers: 1
  • imported: 2025-12-03
environment
Jenkins version: 2.504.2<br/>
Job DSL Plugin: 1.93 (tried also downgraded to 1.92)<br/>
Bitbucket Server Integration Plugin: 4.1.4+ (tested 4.2.0 not working, downgraded to 4.1.4 and not working)<br/>

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions