jenkinsci/bitbucket-branch-source-plugin

Duplicated number of builds run in Builds tab in Bitbucket Server

limeman40 opened this issue · 12 comments

Jenkins and plugins versions report

Jenkins: 2.379
OS: Linux - 5.4.0-1095-azure

Office-365-Connector:4.18.0
ace-editor:1.1
ansible:1.1
ant:481.v7b_09e538fcca
antisamy-markup-formatter:155.v795fb_8702324
apache-httpcomponents-client-4-api:4.5.13-138.v4e7d9a_7b_a_e61
async-http-client:1.9.40.0
authentication-tokens:1.4
azure-acs:1.0.4
azure-ad:267.v5b_dfb_514d9fd
azure-app-service:1.0.2
azure-artifact-manager:109.vaf4232a14e2e
azure-cli:0.9
azure-commons:1.1.3
azure-container-agents:253.vd2f5cd5c5040
azure-container-registry-tasks:0.6.5
azure-credentials:242.vb_f9c4fa_6b_2b_6
azure-credentials-ext:1.0
azure-function:0.3.3
azure-keyvault:146.v0df546b_c98a_5
azure-sdk:118.v43f74dd9ca_dc
azure-vm-agents:822.v3a18fc3d2de1
azure-vmss:0.2.4
badge:1.9.1
blackduck-detect:7.0.0
block-queued-job:0.2.0
blueocean-bitbucket-pipeline:1.25.8
blueocean-commons:1.25.8
blueocean-core-js:1.25.8
blueocean-jwt:1.25.8
blueocean-pipeline-api-impl:1.25.8
blueocean-pipeline-scm-api:1.25.8
blueocean-rest:1.25.8
blueocean-rest-impl:1.25.8
blueocean-web:1.25.8
bootstrap4-api:4.6.0-5
bootstrap5-api:5.2.1-3
bouncycastle-api:2.26
branch-api:2.1051.v9985666b_f6cc
build-user-vars-plugin:1.9
caffeine-api:2.9.3-65.v6a_47d0f4d1fe
changes-since-last-success:0.6
checks-api:1.8.0
cloud-stats:254.v47891b_b_5b_6f6
cloudbees-bitbucket-branch-source:791.vb_eea_a_476405b
cloudbees-folder:6.795.v3e23d3c6f194
command-launcher:90.v669d7ccb_7c31
commons-httpclient3-api:3.1-3
commons-lang3-api:3.12.0-36.vd97de6465d5b_
commons-text-api:1.10.0-27.vb_fa_3896786a_7
conditional-buildstep:1.4.2
config-file-provider:3.11.1
copyartifact:1.47
credentials:1214.v1de940103927
credentials-binding:523.vd859a_4b_122e6
crx-content-package-deployer:1.9
data-tables-api:1.12.1-4
datadog:5.0.0
digitalocean-plugin:1.3.1
display-url-api:2.3.6
docker-commons:1.21
docker-java-api:3.2.13-37.vf3411c9828b9
durable-task:501.ve5d4fc08b0be
echarts-api:5.4.0-1
envinject:2.881.v37c62073ff97
envinject-api:1.199.v3ce31253ed13
extended-read-permission:3.2
extensible-choice-parameter:1.8.0
external-monitor-job:203.v683c09d993b_9
favorite:2.4.1
font-awesome-api:6.2.1-1
generic-webhook-trigger:1.85.2
git:4.14.0
git-client:3.13.0
git-parameter:0.9.18
git-server:99.va_0826a_b_cdfa_d
github:1.36.0
github-api:1.303-400.v35c2d8258028
github-branch-source:1696.v3a_7603564d04
github-pullrequest:0.4.0
gitlab-api:5.0.1-78.v47a_45b_9f78b_7
gitlab-branch-source:642.v9ed86b_b_54384
google-metadata-plugin:0.4
google-oauth-plugin:1.0.7
gradle:2.1.1
handlebars:3.0.8
handy-uri-templates-2-api:2.1.8-22.v77d5b_75e6953
htmlpublisher:1.31
instance-identity:116.vf8f487400980
ionicons-api:31.v4757b_6987003
jackson2-api:2.13.4.20221013-295.v8e29ea_354141
jakarta-activation-api:2.0.1-2
jakarta-mail-api:2.0.1-2
javadoc:226.v71211feb_e7e9
javax-activation-api:1.2.0-5
javax-mail-api:1.6.2-8
jaxb:2.3.7-1
jdk-tool:63.v62d2fd4b_4793
jenkins-design-language:1.25.8
jersey2-api:2.37-1
jjwt-api:0.11.5-77.v646c772fddb_0
jnr-posix-api:3.1.16-1
jobConfigHistory:1187.v2a_b_1ca_54d18d
jquery:1.12.4-1
jquery-detached:1.2.1
jquery3-api:3.6.1-2
jsch:0.1.55.61.va_e9ee26616e7
junit:1160.vf1f01a_a_ea_b_7f
kubernetes-cd:2.3.1
kubernetes-client-api:5.12.2-193.v26a_6078f65a_9
kubernetes-credentials:0.9.0
label-linked-jobs:6.0.1
ldap:2.12
lockable-resources:1069.v726298f53f8c
mailer:438.v02c7f0a_12fa_4
mapdb-api:1.0.9-28.vf251ce40855d
matrix-auth:3.1.5
matrix-project:785.v06b_7f47b_c631
maven-plugin:3.20
mercurial:1260.vdfb_723cdcc81
metrics:4.2.10-405.v60a_9cc74e923
mina-sshd-api-common:2.9.2-50.va_0e1f42659a_a
mina-sshd-api-core:2.9.2-50.va_0e1f42659a_a
momentjs:1.1.1
msbuild:1.30
nexus-jenkins-plugin:3.16.459.vcdf273b_29f8c
node-iterator-api:49.v58a_8b_35f8363
node-sharing-executor:2.0.8
oauth-credentials:0.5
okhttp-api:4.9.3-108.v0feda04578cf
pam-auth:1.10
pipeline-build-step:2.18
pipeline-graph-analysis:195.v5812d95a_a_2f9
pipeline-groovy-lib:621.vb_44ce045b_582
pipeline-input-step:456.vd8a_957db_5b_e9
pipeline-milestone-step:101.vd572fef9d926
pipeline-model-api:2.2118.v31fd5b_9944b_5
pipeline-model-definition:2.2118.v31fd5b_9944b_5
pipeline-model-extensions:2.2118.v31fd5b_9944b_5
pipeline-rest-api:2.27
pipeline-stage-step:296.v5f6908f017a_5
pipeline-stage-tags-metadata:2.2118.v31fd5b_9944b_5
pipeline-stage-view:2.27
pipeline-utility-steps:2.14.0
plain-credentials:139.ved2b_9cf7587b
plugin-util-api:2.18.0
popper-api:1.16.1-3
popper2-api:2.11.6-2
powershell:1.7
pubsub-light:1.17
rebuild:1.34
resource-disposer:0.20
run-condition:1.5
saml:4.372.v89f13e4c9e97
scm-api:621.vda_a_b_055e58f7
script-security:1218.v39ca_7f7ed0a_c
service-fabric:1.6
shelve-project-plugin:3.2
snakeyaml-api:1.33-90.v80dcb_3814d35
ssh:2.6.1
ssh-agent:295.v9ca_a_1c7cc3a_a_
ssh-credentials:305.v8f4381501156
ssh-slaves:2.854.v7fd446b_337c9
ssh2easy:1.4
sshd:3.249.v2dc2ea_416e33
stashNotifier:1.28
strict-crumb-issuer:2.1.0
structs:324.va_f5d6774f3a_d
synopsys-coverity:3.0.1
thinBackup:1.13
timestamper:1.21
token-macro:321.vd7cc1f2a_52c8
trilead-api:2.84.v72119de229b_7
uno-choice:2.6.4
variant:59.vf075fe829ccb
windows-azure-storage:380.va3a027b784f4
windows-slaves:1.8.1
workflow-aggregator:590.v6a_d052e5a_a_b_5
workflow-api:1200.v8005c684b_a_c6
workflow-basic-steps:994.vd57e3ca_46d24
workflow-cps:3536.vb_8a_6628079d5
workflow-cps-global-lib:609.vd95673f149b_b
workflow-durable-task-step:1217.v38306d8fa_b_5c
workflow-job:1254.v3f64639b_11dd
workflow-multibranch:716.vc692a_e52371b_
workflow-scm-step:400.v6b_89a_1317c9a_
workflow-step-api:639.v6eca_cd8c04a_a_
workflow-support:839.v35e2736cfd5c
ws-cleanup:0.43

What Operating System are you using (both controller, and any agents involved in the problem)?

Ubuntu: 18.04

Reproduction steps

Create a PR from BitBucket

Expected Results

It showing just the single build of a PR

Actual Results

It is duplicating the runs of the branch in the Build tab in BitBucket

Anything else?

No response

Do you mean like this:

  • There is a pull request PR-1 from branch feature/widget to branch master.
  • The latest commit on branch feature/widget is 2660a66c4252c7ed0c0c6d78dea1a07547fe1fa2.
  • Jenkins builds commit 2660a66c4252c7ed0c0c6d78dea1a07547fe1fa2 in job PR-1 run 1.
  • Jenkins also builds commit 2660a66c4252c7ed0c0c6d78dea1a07547fe1fa2 in job feature%2Fwidget run 1.
  • When you view PR-1 in Bitbucket Server, it shows both of these builds. But you don't want to see job feature%2Fwidget run 1 there.

If so, fixing this would require the Bitbucket Branch Source plugin to tell Bitbucket Server that feature%2Fwidget run 1 belongs to the feature/widget branch and not to any pull request.

Bitbucket Server currently provides two ways to report a build status:

Both of these are documented as taking a "ref" property in the request body. If Bitbucket Branch Source posted e.g. "ref": "refs/heads/feature/widget" there, then Bitbucket Server could perhaps hide the build status from pull requests. However, I don't know whether Bitbucket Server actually uses the "ref" property for that.

Which version of Bitbucket Server are you using?

Atlassian Bitbucket v8.5.1

Jenkins is not setup to build feature branches. We do this due to IAR license seat limitations.

Your saying though any feature request would show this duplicate the way it works now?

Any updates on this? It is been while

Does Bitbucket Server show the same Jenkins build twice, i.e. both occurrences link to the same URL in Jenkins?

Yes the URL is the same on the duplicates. Am guessing one is from the feature branch and one is from the PR.

Is it a multibranch project in Jenkins? If so, a build of a branch would not have the same URL in Jenkins as a build of a pull request.

Can you use the Bitbucket Server REST APIs to query the builds and show the JSON results? Perhaps the Bitbucket Branch Source plugin has reported a build status via the old API but something else has reported a build status for the same Jenkins run via the newer per-repository API.

Sure will try this next week and get back to you.

The requests would be

I don't remember whether build statuses posted via the deprecated API can be retrieved via the current per-repository API and vice versa. Probably not. Therefore use both APIs to query.

So what I am seeing when I run that command is some of the keys instead of being the commit IDs appear to be URLs.

I rather not show you the JSON results as they include URLs on how to get to our Jenkins instance.

The Bitbucket Branch Source plugin always uses an MD5 hash as the key of a build status; it's not a commit ID.


private static String getBuildKey(@NonNull Run<?, ?> build, String branch,
boolean shareBuildKeyBetweenBranchAndPR) {
// When the ExcludeOriginPRBranchesSCMHeadFilter filter is active, we want the
// build status key to be the same between the branch project and the PR project.
// This is to avoid having two build statuses when a branch goes into PR and
// it was already built at least once as a branch.
// So the key we use is the branch name.
String key;
if (shareBuildKeyBetweenBranchAndPR) {
String folderName = build.getParent().getParent().getFullName();
key = String.format("%s/%s", folderName, branch);
} else {
key = build.getParent().getFullName(); // use the job full name as the key for the status
}
return key;
}

If you have an URL there, then the build status has been reported by something else. Perhaps by the stashNotifier plugin that is in your list.

@KalleOlaviNiemitalo you are correct these are indeed coming from stashNotifer plugin. I have updated a couple of my pipelines to not call this plugin in the POST builds section and I am seeing the correct behavior. We can now close this case as it is not a bug from this plugin