-
Type:
Improvement
-
Resolution: Unresolved
-
Priority:
Critical
-
Component/s: atlassian-bitbucket-server-integration-plugin
-
None
-
Environment:Host OS - Amazon Linux
Server - Container on EKS - Using latestjenkins/jenkins:lts from Dockerhub
Agents - Containers on EKS - Using latest jenkins/inbound-agent from Dockerhub
Jenkins: 2.528.1
OS: Linux - 6.1.155-176.282.amzn2023.aarch64
Java: 21.0.8 - Eclipse Adoptium (OpenJDK 64-Bit Server VM)
---
antisamy-markup-formatter:173.v680e3a_b_69ff3
apache-httpcomponents-client-4-api:4.5.14-269.vfa_2321039a_83
apache-httpcomponents-client-5-api:5.5-170.v023de017ccd7
asm-api:9.9-185.va_6c6b_3348b_c3
atlassian-bitbucket-server-integration:4.2.0
authentication-tokens:1.144.v5ff4a_5ec5c33
aws-credentials:254.v978a_5e206a_d7
aws-java-sdk-ec2:1.12.780-480.v4a_0819121a_9e
aws-java-sdk-minimal:1.12.780-480.v4a_0819121a_9e
aws-java-sdk2-core:2.33.4-62.vc1a_8df64b_4c9
aws-java-sdk2-ec2:2.33.4-62.vc1a_8df64b_4c9
basic-branch-build-strategies:275.vde2351b_4a_58b_
blueocean:1.27.23
blueocean-bitbucket-pipeline:1.27.23
blueocean-commons:1.27.23
blueocean-config:1.27.23
blueocean-core-js:1.27.23
blueocean-dashboard:1.27.23
blueocean-display-url:2.4.4
blueocean-events:1.27.23
blueocean-git-pipeline:1.27.23
blueocean-github-pipeline:1.27.23
blueocean-i18n:1.27.23
blueocean-jwt:1.27.23
blueocean-personalization:1.27.23
blueocean-pipeline-api-impl:1.27.23
blueocean-pipeline-editor:1.27.23
blueocean-pipeline-scm-api:1.27.23
blueocean-rest:1.27.23
blueocean-rest-impl:1.27.23
blueocean-web:1.27.23
bootstrap5-api:5.3.8-895.v4d0d8e47fea_d
bouncycastle-api:2.30.1.82-277.v70ca_0b_877184
branch-api:2.1255.v2f5fe203584a_
caffeine-api:3.2.2-178.v353b_8428ed56
checks-api:373.vfe7645102093
cloudbees-bitbucket-branch-source:937.2.1
cloudbees-folder:6.1062.v2877b_d6b_b_eeb_
command-launcher:123.v37cfdc92ef67
commons-collections4-api:4.5.0-8.va_d5448ef9011
commons-compress-api:1.28.0-1
commons-lang3-api:3.19.0-104.v12125f33a_255
commons-text-api:1.14.0-194.v804a_dc3a_1b_d8
configuration-as-code:2006.v001a_2ca_6b_574
configuration-as-code-groovy:1.1
credentials:1447.v4cb_b_539b_5321
credentials-binding:702.vfe613e537e88
dark-theme:574.va_19f05d54df5
data-tables-api:2.3.4-1451.vb_0b_5238f9054
display-url-api:2.217.va_6b_de84cc74b_
durable-task:605.v9a_b_9040c9970
echarts-api:6.0.0-1165.vd1283a_3e37d4
eddsa-api:0.3.0.1-19.vc432d923e5ee
favorite:2.253.v9b_413168133b_
font-awesome-api:7.1.0-882.v1dfb_771e3278
git:5.8.0
git-client:6.4.0
github:1.45.0
github-api:1.330-492.v3941a_032db_2a_
github-branch-source:1911.vc09e01781005
gson-api:2.13.2-173.va_a_092315913c
handy-uri-templates-2-api:2.1.8-36.v85e4cb_234a_13
htmlpublisher:427
http_request:1.22
instance-identity:203.v15e81a_1b_7a_38
ionicons-api:94.vcc3065403257
jackson2-api:2.20.0-420.v8a_08b_d57ca_05
jakarta-activation-api:2.1.3-2
jakarta-mail-api:2.1.3-3
jakarta-xml-bind-api:4.0.5-3.v3d5b_a_73965b_9
javax-activation-api:1.2.0-8
javax-mail-api:1.6.2-11
jaxb:2.3.9-133.vb_ec76a_73f706
jdk-tool:83.v417146707a_3d
jenkins-bitbucket-ignore-committer-strategy-plugin:1.1.8
jenkins-build-event-notifier-plugin:1.2.0
jenkins-design-language:1.27.23
jenkins-spectrum-integration-plugin:1.8.1
jjwt-api:0.11.5-120.v0268cf544b_89
joda-time-api:2.14.0-149.v1c3ce991d1b_9
jquery3-api:3.7.1-619.vdb_10e002501a_
json-api:20250517-173.v596efb_962a_31
json-path-api:2.9.0-190.veefca_05d5477
junit:1369.v15da_00283f06
kubernetes:4384.v1b_6367f393d9
kubernetes-client-api:7.3.1-256.v788a_0b_787114
kubernetes-credentials:206.vde31a_b_0f71a_c
ldap:793.v754d6b_41b_ea_4
lockable-resources:1438.v3c0f8c9e2060
mailer:522.va_995fa_cfb_8b_d
mapdb-api:1.0.9-44.va_1e1310c9118
mask-passwords:212.v4967a_a_73b_506
matrix-auth:3.2.8
metrics:4.2.37-489.vb_6db_69b_ce753
mina-sshd-api-common:2.16.0-167.va_269f38cc024
mina-sshd-api-core:2.16.0-167.va_269f38cc024
okhttp-api:4.12.0-195.vc02552c04ffd
pipeline-build-step:571.v08a_fffd4b_0ce
pipeline-graph-analysis:245.v88f03631a_b_21
pipeline-graph-view:661.v6003f4542123
pipeline-groovy-lib:776.vfee5327b_b_a_5b_
pipeline-input-step:534.v352f0a_e98918
pipeline-milestone-step:138.v78ca_76831a_43
pipeline-model-api:2.2277.v00573e73ddf1
pipeline-model-definition:2.2277.v00573e73ddf1
pipeline-model-extensions:2.2277.v00573e73ddf1
pipeline-rest-api:2.38
pipeline-stage-step:322.vecffa_99f371c
pipeline-stage-tags-metadata:2.2277.v00573e73ddf1
pipeline-stage-view:2.38
pipeline-utility-steps:2.20.0
plain-credentials:199.v9f8e1f741799
plugin-util-api:6.1192.v30fe6e2837ff
prism-api:1.30.0-630.va_e19d17f83b_0
prometheus:819.v50953a_c560dd
pubsub-light:1.19
saml:4.583.vc68232f7018a_
scm-api:712.v8846fdd68c88
script-security:1385.v7d2d9ec4d909
snakeyaml-api:2.5-143.v93b_c004f89de
sse-gateway:1.28
ssh-credentials:361.vb_f6760818e8c
sshd:3.374.v19b_d59ce6610
structs:353.v261ea_40a_80fb_
subversion:1292.ve8cf25770ee3
theme-manager:327.v780d7096ec29
timestamper:1.30
token-macro:477.vd4f0dc3cb_cf1
trilead-api:2.209.v0e69b_c43c245
variant:70.va_d9f17f859e0
workflow-aggregator:608.v67378e9d3db_1
workflow-api:1384.vdc05a_48f535f
workflow-basic-steps:1098.v808b_fd7f8cf4
workflow-cps:4218.vff679a_5c0f3a_
workflow-durable-task-step:1464.v2d3f5c68f84c
workflow-job:1559.va_a_533730b_ea_d
workflow-multibranch:821.vc3b_4ea_780798
workflow-scm-step:452.vdf1ca_c8d3a_87
workflow-step-api:710.v3e456cc85233
workflow-support:1004.veee3a_d67cdb_9Host OS - Amazon Linux Server - Container on EKS - Using latestjenkins/jenkins:lts from Dockerhub Agents - Containers on EKS - Using latest jenkins/inbound-agent from Dockerhub Jenkins: 2.528.1 OS: Linux - 6.1.155-176.282.amzn2023.aarch64 Java: 21.0.8 - Eclipse Adoptium (OpenJDK 64-Bit Server VM) --- antisamy-markup-formatter:173.v680e3a_b_69ff3 apache-httpcomponents-client-4-api:4.5.14-269.vfa_2321039a_83 apache-httpcomponents-client-5-api:5.5-170.v023de017ccd7 asm-api:9.9-185.va_6c6b_3348b_c3 atlassian-bitbucket-server-integration:4.2.0 authentication-tokens:1.144.v5ff4a_5ec5c33 aws-credentials:254.v978a_5e206a_d7 aws-java-sdk-ec2:1.12.780-480.v4a_0819121a_9e aws-java-sdk-minimal:1.12.780-480.v4a_0819121a_9e aws-java-sdk2-core:2.33.4-62.vc1a_8df64b_4c9 aws-java-sdk2-ec2:2.33.4-62.vc1a_8df64b_4c9 basic-branch-build-strategies:275.vde2351b_4a_58b_ blueocean:1.27.23 blueocean-bitbucket-pipeline:1.27.23 blueocean-commons:1.27.23 blueocean-config:1.27.23 blueocean-core-js:1.27.23 blueocean-dashboard:1.27.23 blueocean-display-url:2.4.4 blueocean-events:1.27.23 blueocean-git-pipeline:1.27.23 blueocean-github-pipeline:1.27.23 blueocean-i18n:1.27.23 blueocean-jwt:1.27.23 blueocean-personalization:1.27.23 blueocean-pipeline-api-impl:1.27.23 blueocean-pipeline-editor:1.27.23 blueocean-pipeline-scm-api:1.27.23 blueocean-rest:1.27.23 blueocean-rest-impl:1.27.23 blueocean-web:1.27.23 bootstrap5-api:5.3.8-895.v4d0d8e47fea_d bouncycastle-api:2.30.1.82-277.v70ca_0b_877184 branch-api:2.1255.v2f5fe203584a_ caffeine-api:3.2.2-178.v353b_8428ed56 checks-api:373.vfe7645102093 cloudbees-bitbucket-branch-source:937.2.1 cloudbees-folder:6.1062.v2877b_d6b_b_eeb_ command-launcher:123.v37cfdc92ef67 commons-collections4-api:4.5.0-8.va_d5448ef9011 commons-compress-api:1.28.0-1 commons-lang3-api:3.19.0-104.v12125f33a_255 commons-text-api:1.14.0-194.v804a_dc3a_1b_d8 configuration-as-code:2006.v001a_2ca_6b_574 configuration-as-code-groovy:1.1 credentials:1447.v4cb_b_539b_5321 credentials-binding:702.vfe613e537e88 dark-theme:574.va_19f05d54df5 data-tables-api:2.3.4-1451.vb_0b_5238f9054 display-url-api:2.217.va_6b_de84cc74b_ durable-task:605.v9a_b_9040c9970 echarts-api:6.0.0-1165.vd1283a_3e37d4 eddsa-api:0.3.0.1-19.vc432d923e5ee favorite:2.253.v9b_413168133b_ font-awesome-api:7.1.0-882.v1dfb_771e3278 git:5.8.0 git-client:6.4.0 github:1.45.0 github-api:1.330-492.v3941a_032db_2a_ github-branch-source:1911.vc09e01781005 gson-api:2.13.2-173.va_a_092315913c handy-uri-templates-2-api:2.1.8-36.v85e4cb_234a_13 htmlpublisher:427 http_request:1.22 instance-identity:203.v15e81a_1b_7a_38 ionicons-api:94.vcc3065403257 jackson2-api:2.20.0-420.v8a_08b_d57ca_05 jakarta-activation-api:2.1.3-2 jakarta-mail-api:2.1.3-3 jakarta-xml-bind-api:4.0.5-3.v3d5b_a_73965b_9 javax-activation-api:1.2.0-8 javax-mail-api:1.6.2-11 jaxb:2.3.9-133.vb_ec76a_73f706 jdk-tool:83.v417146707a_3d jenkins-bitbucket-ignore-committer-strategy-plugin:1.1.8 jenkins-build-event-notifier-plugin:1.2.0 jenkins-design-language:1.27.23 jenkins-spectrum-integration-plugin:1.8.1 jjwt-api:0.11.5-120.v0268cf544b_89 joda-time-api:2.14.0-149.v1c3ce991d1b_9 jquery3-api:3.7.1-619.vdb_10e002501a_ json-api:20250517-173.v596efb_962a_31 json-path-api:2.9.0-190.veefca_05d5477 junit:1369.v15da_00283f06 kubernetes:4384.v1b_6367f393d9 kubernetes-client-api:7.3.1-256.v788a_0b_787114 kubernetes-credentials:206.vde31a_b_0f71a_c ldap:793.v754d6b_41b_ea_4 lockable-resources:1438.v3c0f8c9e2060 mailer:522.va_995fa_cfb_8b_d mapdb-api:1.0.9-44.va_1e1310c9118 mask-passwords:212.v4967a_a_73b_506 matrix-auth:3.2.8 metrics:4.2.37-489.vb_6db_69b_ce753 mina-sshd-api-common:2.16.0-167.va_269f38cc024 mina-sshd-api-core:2.16.0-167.va_269f38cc024 okhttp-api:4.12.0-195.vc02552c04ffd pipeline-build-step:571.v08a_fffd4b_0ce pipeline-graph-analysis:245.v88f03631a_b_21 pipeline-graph-view:661.v6003f4542123 pipeline-groovy-lib:776.vfee5327b_b_a_5b_ pipeline-input-step:534.v352f0a_e98918 pipeline-milestone-step:138.v78ca_76831a_43 pipeline-model-api:2.2277.v00573e73ddf1 pipeline-model-definition:2.2277.v00573e73ddf1 pipeline-model-extensions:2.2277.v00573e73ddf1 pipeline-rest-api:2.38 pipeline-stage-step:322.vecffa_99f371c pipeline-stage-tags-metadata:2.2277.v00573e73ddf1 pipeline-stage-view:2.38 pipeline-utility-steps:2.20.0 plain-credentials:199.v9f8e1f741799 plugin-util-api:6.1192.v30fe6e2837ff prism-api:1.30.0-630.va_e19d17f83b_0 prometheus:819.v50953a_c560dd pubsub-light:1.19 saml:4.583.vc68232f7018a_ scm-api:712.v8846fdd68c88 script-security:1385.v7d2d9ec4d909 snakeyaml-api:2.5-143.v93b_c004f89de sse-gateway:1.28 ssh-credentials:361.vb_f6760818e8c sshd:3.374.v19b_d59ce6610 structs:353.v261ea_40a_80fb_ subversion:1292.ve8cf25770ee3 theme-manager:327.v780d7096ec29 timestamper:1.30 token-macro:477.vd4f0dc3cb_cf1 trilead-api:2.209.v0e69b_c43c245 variant:70.va_d9f17f859e0 workflow-aggregator:608.v67378e9d3db_1 workflow-api:1384.vdc05a_48f535f workflow-basic-steps:1098.v808b_fd7f8cf4 workflow-cps:4218.vff679a_5c0f3a_ workflow-durable-task-step:1464.v2d3f5c68f84c workflow-job:1559.va_a_533730b_ea_d workflow-multibranch:821.vc3b_4ea_780798 workflow-scm-step:452.vdf1ca_c8d3a_87 workflow-step-api:710.v3e456cc85233 workflow-support:1004.veee3a_d67cdb_9
We have a large repository in Bitbucket server,
* 10GB in size (as per Bitbucket UI)
* 2500 branches approximately
* 150 open Pull Requests
When this repository is configured for a multi branch pipeline, we've noticed that the refspec that is set by the BitbucketSCMSource to be the following.
+refs/heads/*:refs/remotes/origin/*
We first noticed at the checkout stage that we run after a pod is allocated, which was cloning the entire repository than the branch it requires, taking a long time (5 minutes+). We then custom set the refspec to the checkout to be a specific branch or the PR, the performance changed back to what we used to have with cloudbees-bitbucket-branch-source.
However, for pull requests, it seems like even before the job reaches the steps in the Jenkinsfile it is doing a full repository clone, which takes again around 5 mins, before we see "[Pipeline] Start of Pipeline" line on the logs.
To make sure this was the problem, we got the code for the plugin and made the following change to the BitbucketSCMSource.java, and the performance is back to what normal, which is few seconds to start the job.
diff --git a/src/main/java/com/atlassian/bitbucket/jenkins/internal/scm/BitbucketSCMSource.java b/src/main/java/com/atlassian/bitbucket/jenkins/internal/scm/BitbucketSCMSource.java index 06cf811..7d62922 100644 --- a/src/main/java/com/atlassian/bitbucket/jenkins/internal/scm/BitbucketSCMSource.java +++ b/src/main/java/com/atlassian/bitbucket/jenkins/internal/scm/BitbucketSCMSource.java @@ -70,7 +70,6 @@ import static org.apache.commons.lang3.StringUtils.isNotBlank; public class BitbucketSCMSource extends SCMSource { private static final Logger LOGGER = Logger.getLogger(BitbucketSCMSource.class.getName()); - private static final String REFSPEC_DEFAULT = "+refs/heads/*:refs/remotes/@\{remote}/*"; @UpgradeHandled(handledBy = "Uses the same remote variable as REFSPEC_DEFAULT", removeAnnotationInVersion = "4.1") private static final String REFSPEC_TAGS = "+refs/tags/*:refs/remotes/@\{remote}/*"; @@ -161,7 +160,11 @@ public class BitbucketSCMSource extends SCMSource { if (head.getClass().equals(BitbucketTagSCMHead.class)) { builder.withRefSpec(REFSPEC_TAGS); } else { - builder.withRefSpec(REFSPEC_DEFAULT); + SCMHead refSpecHead = head; + if (head instanceof BitbucketPullRequestSCMHead) { + refSpecHead = ((BitbucketPullRequestSCMHead) head).getTarget(); + } + builder.withRefSpec("+refs/heads/" + refSpecHead.getName() + ":refs/remotes/@\{remote}/" + refSpecHead.getName()); } builder.withTraits(traits);
We've tested this with branches and PRs.
- On branch builds, the build starts almost instantly, and the checkouts running later are much faster as well.
- On PRs, the start time is has halved (better, but not best), as it still wait for minutes doing
git fetch --no-tags --force --progress – https://.../scm/.../....git +refs/heads/:refs/remotes/origin/ # timeout=10at the beginning of the job before it reaches steps in the Jenkinsfile. Later checkout are faster.
As we run these builds in agents in Kubernetes, its kind of a waste doing a clone in the server side like this and merging the change, which will then again be done on an agent at a later point. Would be even better if we could skip this step, or use the Bitbucket REST API to check the mergeability of the PR instead.
Think the above mentioned change is still worth going in as its a step improvement. Happy to raise a PR.
Will be investigating further to see how we could make this even better. Will report back if there's any further updates.
Update 03/Nov/2025 14:17:
- For the time being we've switched back to cloudbees-bitbucket-branch-source plugin for our large repository, as the cost of the fetch of few mins adds up to the total time PRs have to queue up to be merged to mainline. I've raised a separate feature request for this JENKINS-76259
- It would be great to get the change proposed in this task to fix the refspecs as it will improve performance of all builds in general.