jenkinsci / jenkinsci/branch-api-plugin
Manually triggered builds in Multibranch Pipeline do not update git commit hash in 'scm-last-seen-revision-hash.xml' so that branch indexing triggers duplicated build
- Dominant language
- Java
- Stars
- 39
- Forks
- 154
- PR merge metrics
- No merged PRs in 30d
Description
### Jenkins and plugins versions report
Environment
```text
Jenkins: 2.528.3
OS: Linux - 5.14.0-611.16.1.el9_7.x86_64
Java: 17.0.17 - Red Hat, Inc. (OpenJDK 64-Bit Server VM)
---
additional-metrics:207.v0407e7fe201b_
analysis-model-api:13.17.0-931.v730d8659ea_9c
ansicolor:1.0.6
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
audit-trail:436.vc0d1e79fc5a_3
authentication-tokens:1.144.v5ff4a_5ec5c33
authorize-project:2.0.0
blueocean:1.27.25
blueocean-autofavorite:1.2.5
blueocean-bitbucket-pipeline:1.27.25
blueocean-commons:1.27.25
blueocean-config:1.27.25
blueocean-core-js:1.27.25
blueocean-dashboard:1.27.25
blueocean-display-url:2.4.4
blueocean-events:1.27.25
blueocean-git-pipeline:1.27.25
blueocean-github-pipeline:1.27.25
blueocean-i18n:1.27.25
blueocean-jira:1.27.25
blueocean-jwt:1.27.25
blueocean-personalization:1.27.25
blueocean-pipeline-api-impl:1.27.25
blueocean-pipeline-editor:1.27.25
blueocean-pipeline-scm-api:1.27.25
blueocean-rest:1.27.25
blueocean-rest-impl:1.27.25
blueocean-web:1.27.25
bootstrap5-api:5.3.8-895.v4d0d8e47fea_d
bouncycastle-api:2.30.1.82-277.v70ca_0b_877184
branch-api:2.1268.v044a_87612da_8
build-history-manager:1.14.0
caffeine-api:3.2.3-194.v31a_b_f7a_b_5a_81
checks-api:373.vfe7645102093
cloudbees-bitbucket-branch-source:937.2.2
cloudbees-folder:6.1073.va_7888eb_dd514
code-coverage-api:4.99.0
command-launcher:123.v37cfdc92ef67
commons-collections4-api:4.5.0-8.va_d5448ef9011
commons-compress-api:1.28.0-2
commons-lang3-api:3.20.0-109.ve43756e2d2b_4
commons-text-api:1.15.0-210.v7480a_da_70b_9e
configuration-as-code:2006.v001a_2ca_6b_574
copyartifact:770.va_6c69e063442
coverage:2.3060.v035a_5557cdb_c
credentials:1453.v9b_a_29777a_b_fd
credentials-binding:702.vfe613e537e88
data-tables-api:2.3.5-1482.vb_47a_3c19f78c
description-setter:264.v1957f215dcd5
display-url-api:2.217.va_6b_de84cc74b_
docker-commons:457.v0f62a_94f11a_3
docker-workflow:634.vedc7242b_eda_7
dtkit-api:3.0.3
durable-task:639.vefb_3d8372f6d
echarts-api:6.0.0-1165.vd1283a_3e37d4
eddsa-api:0.3.0.1-19.vc432d923e5ee
email-ext:1933.v45cec755423f
favorite:2.253.v9b_413168133b_
font-awesome-api:7.1.0-882.v1dfb_771e3278
forensics-api:3.1772.v99ca_3d83b_9fa_
fortify:23.1.40
generic-webhook-trigger:2.4.1
git:5.8.1
git-client:6.4.1
git-server:137.ve0060b_432302
github:1.45.0
github-api:1.330-492.v3941a_032db_2a_
github-branch-source:1917.v9ee8a_39b_3d0d
gitlab-api:6.2.0-111.vf174d6b_8c12e
gitlab-branch-source:739.v9781b_1cdb_72a_
gitlab-plugin:1.9.11
gradle:2.16.1149.v711b_998b_0532
gson-api:2.13.2-173.va_a_092315913c
handy-uri-templates-2-api:2.1.8-38.vcea_5d521d5f3
htmlpublisher:427
http_request:1.24
instance-identity:203.v15e81a_1b_7a_38
ionicons-api:94.vcc3065403257
jackson2-api:2.20.1-423.v13951f6b_6532
jakarta-activation-api:2.1.4-1
jakarta-mail-api:2.1.5-1
jakarta-xml-bind-api:4.0.6-10.v9b_7e1d1fc40b_
javadoc:354.vee1a_660b_4990
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-design-language:1.27.25
jenkins-path-aware-build-strategy-plugin:0.1.0-SNAPSHOT (private-b6bc10b1-root)
jersey2-api:2.47-165.ve7809a_3e87e0
jersey3-api:3.1.11-4.v77818819c2e1
jira:3.20
jjwt-api:0.11.5-120.v0268cf544b_89
job-dsl:1.93
jobConfigHistory:1356.ve360da_6c523a_
jobcacher:764.v098c635e4315
joda-time-api:2.14.0-149.v1c3ce991d1b_9
jquery3-api:3.7.1-619.vdb_10e002501a_
jsch:0.2.16-95.v3eecb_55fa_b_78
json-api:20250517-173.v596efb_962a_31
json-path-api:2.10.0-202.va_9cc16c1e476
jsoup:1.21.2-66.v6ea_38164b_8a_2
junit:1369.v15da_00283f06
ldap:793.v754d6b_41b_ea_4
lockable-resources:1438.v3c0f8c9e2060
mailer:525.v2458b_d8a_1a_71
mapdb-api:1.0.9-44.va_1e1310c9118
matrix-auth:3.2.9
matrix-project:870.v9db_fcfc2f45b_
maven-plugin:3.27
mercurial:1323.ve69d2a_db_8a_b_d
mina-sshd-api-common:2.16.0-167.va_269f38cc024
mina-sshd-api-core:2.16.0-167.va_269f38cc024
nexus-jenkins-plugin:3.27.0-01
okhttp-api:4.12.0-195.vc02552c04ffd
oss-symbols-api:424.ved751e062911
pam-auth:1.12
pipeline-build-step:571.v08a_fffd4b_0ce
pipeline-graph-analysis:245.v88f03631a_b_21
pipeline-groovy-lib:787.ve2fef0efdca_6
pipeline-input-step:540.v14b_100d754dd
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-usage-plugin:4.10
plugin-util-api:6.1192.v30fe6e2837ff
prism-api:1.30.0-630.va_e19d17f83b_0
pubsub-light:1.19
resource-disposer:0.25
rest-list-parameter:348.v9506fdc4b_d07
role-strategy:848.va_a_ea_673cf0b_c
saml:4.590.v6170b_1013da_f
scm-api:724.v7d839074eb_5c
script-security:1385.v7d2d9ec4d909
select2-api:4.0.13-8
simple-queue:1.4.7
snakeyaml-api:2.5-143.v93b_c004f89de
sse-gateway:1.28
ssh-credentials:361.vb_f6760818e8c
ssh-slaves:3.1085.vc64d040efa_85
ssh-steps:2.0.79.v1d1b_5f76dda_8
sshd:3.374.v19b_d59ce6610
structs:362.va_b_695ef4fdf9
subversion:1292.ve8cf25770ee3
timestamper:1.30
token-macro:477.vd4f0dc3cb_cf1
trilead-api:2.284.v1974ea_324382
uno-choice:2.8.8
variant:70.va_d9f17f859e0
view-job-filters:405.v9a_5fddc9230d
warnings-ng:12.9848.v5603977006f2
workflow-aggregator:608.v67378e9d3db_1
workflow-api:1384.vdc05a_48f535f
workflow-basic-steps:1098.v808b_fd7f8cf4
workflow-cps:4238.va_6fb_65c1f699
workflow-durable-task-step:1464.v2d3f5c68f84c
workflow-job:1559.va_a_533730b_ea_d
workflow-multibranch:821.vc3b_4ea_780798
workflow-scm-step:466.va_d69e602552b_
workflow-step-api:710.v3e456cc85233
workflow-support:1010.vb_b_39488a_9841
ws-cleanup:0.49
```
### What Operating System are you using (both controller, and any agents involved in the problem)?
Up-to-date RHEL distributions
### Reproduction steps
### Preparation
1. Have a git repository with at least one branch and a Jenkins file set up in that branch, any 'Hello world' will do it.
a. Our repositories are hosted in a commercial, self hosted GitHub instance.
b. The latest commit on the test branch is referred to as commit `A`.
2. Create a multibranch pipeline for that repository
a. Branch Source: `GitHub`
b. Provide Credentials / HTTPS URL
c. Discover branches: `all branches`
d. Discover pull requests from origin: Strategy `Merging the pull requests with the current target branch revision`
e. Advanced clone behaviours: Timeout `10` minutes (everything else is blank)
f. Have `Git LFS pull after checkout` present
g. Property strategy: `All branches get the same properties`
* Suppress automatic SCM triggering
* Branch names to build automatically: `^.*$`
* Suppress strategy: `For matching branches suppress builds triggered by webhooks (continue to trigger from indexing)`
h. Configure the path to your Jenkinsfile in your test branch
i. Scan Repository Triggers: periodically if not otherwise run (checked)
* Interval: `1 day`
j. Orphaned Item Strategy: `Discard old items`
* Days to keep old items: `1`
3. In your new Multibranch Pipeline, ensure that the routine behind the "Scan repository Now"-Button was triggered, usually done automatically, so the test branch should now be visible as own job
4. Access the file system on the Jenkins master, e.g. via SSH, navigate to the folder of the test branch job we just created, e.g. `/jobs//jobs//branches//`
a. `` can be looked up in the global Jenkins-settings: `https:///manage/configure` under `Jenkins home directory`
b. In that directory, you should find 2 files: `scm-last-seen-revision-hash.xml` and `scm-revision-hash.xml`
5. Inspect both the files `scm-last-seen-revision-hash.xml` and `scm-revision-hash.xml`, assert that the included commit hash is equal.
It will be the commit hash for commit `A`. That is because of the initial repository scan.
### Reproducing the issue
6. Create a new commit (e.g., commit `B`) and push it onto the test branch
7. Check the remote repository that the new commit on the test branch is present
8. Trigger a manual build for the test branch with the new commit
9. Check the commit hashes in the files `scm-last-seen-revision-hash.xml` and `scm-revision-hash.xml`
Now, both the files still point to the same commit `A` which is the last one built by the 'Scan repository now'-button.
But, expected would be that the files get updated as there actually is now a new build of the latest commit `B` already present.
Instead, whenever a new run of 'Scan repository now' is triggered (be it cron, be it manually), a new build is scheduled.
The Scan log even shows
```
Changes detected: main ( → )
Scheduled build for branch:
```
If now no change is present on the test branch, the next 'Scan repository now' run will report in the log:
```
No changes detected: (still at )
```
This would be expected also if there is a change present, followed by a manual trigger.
However, we did not test if the bug can also be seen with Push Triggers.
### Expected Results
'Scan repository now' should only trigger a new build if the build before does not use the same commit hash as source.
The build result does not matter.
### Actual Results
'Scan repository now' is always triggering a new build if there was a change since last build triggered by 'Scan repository now' (branch indexing), ignoring manual builds which happened inbetween and did the job already.
### Anything else?
Probably the same behaviour can be observed with Push Triggers, but we did not test it. Though, I would consider this being a bug as well.
It might be this is related to
#792 [JENKINS-74839] Branch Indexing / SCM event may trigger duplicated builds
[#22643 [JENKINS-50191] Multibranch Pipeline tends to keep rebuilding same commits](https://github.com/jenkinsci/jenkins/issues/22643)
### Are you interested in contributing a fix?
_No response_
Contributor guide
Research direction
Start with the branch job files scm-last-seen-revision-hash.xml and scm-revision-hash.xml, then follow the manual build and Scan repository Now flows described in the reproduction steps. Verify how each flow records the built revision; done means a scan does not schedule another build when a manual build already used the latest commit hash.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- git, java
- Domain
- backend, ci-cd
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100