-
Bug
-
Resolution: Unresolved
-
Major
-
Jenkins version: 2.504.2
Job DSL Plugin: 1.93 (tried also downgraded to 1.92)
Bitbucket Server Integration Plugin: 4.1.4+ (tested 4.2.0 not working, downgraded to 4.1.4 and not working)
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="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:
- Create nested gitSCM block with extensions
- Add extension references in main extensions block
- Maintain backward compatibility with older plugin versions if possible