Skip to content

Fix disabled multibranch build notification#26113

Closed
LakshyaBagani wants to merge 7 commits intojenkinsci:masterfrom
LakshyaBagani:fix-disabled-multibranch-build-notification
Closed

Fix disabled multibranch build notification#26113
LakshyaBagani wants to merge 7 commits intojenkinsci:masterfrom
LakshyaBagani:fix-disabled-multibranch-build-notification

Conversation

@LakshyaBagani
Copy link
Contributor

Fixes #16678

Description

When trying to trigger a build of a branch job in a disabled multibranch project, the UI incorrectly showed "Build Scheduled" notification even though the build was not actually scheduled. The queue rejected the build (returned null), but the code sent a 302 redirect which the JavaScript treated as success.

Changes

  1. Updated isBuildable() method: Now checks if the parent ParameterizedJob (e.g., multibranch project) is disabled before allowing builds
  2. Fixed error handling in doBuild(): Changed from returning 302 redirect to throwing 409 CONFLICT when schedule2() returns null
  3. Fixed JavaScript response handling: Changed from checking rsp.ok (which includes 302) to checking rsp.status === 201 specifically

Testing done

Manual testing performed:

  1. Created a Multibranch Pipeline project
  2. Disabled the multibranch project via configuration page
  3. Attempted to trigger a build on a branch job within the disabled multibranch
  4. Before fix: UI showed "Build Scheduled" notification (incorrect)
  5. After fix: UI shows "Build failed" notification (correct)
  6. Verified browser console shows proper error response (409 CONFLICT)
  7. Verified that builds work correctly when multibranch is enabled
  8. Verified that builds work correctly for regular (non-multibranch) projects

Tested on: Jenkins 2.541-SNAPSHOT

Proposed changelog entries

  • Fix false "Build Scheduled" notification when attempting to build branch jobs in disabled multibranch projects

Proposed changelog category

/label bug

Proposed upgrade guidelines

N/A

Submitter checklist

  • The issue, if it exists, is well-described.
  • The changelog entries and upgrade guidelines are appropriate for the audience affected by the change (users or developers, depending on the change) and are in the imperative mood (see examples). Fill in the Proposed upgrade guidelines section only if there are breaking changes or changes that may require extra steps from users during upgrade.
  • There is automated testing or an explanation as to why this change has no tests.
    • Manual testing performed as described above. This is a UI/behavior fix that requires testing with actual multibranch projects.
  • New public classes, fields, and methods are annotated with @Restricted or have @since TODO Javadocs, as appropriate.
    • N/A - No new public APIs added
  • New deprecations are annotated with @Deprecated(since = "TODO") or @Deprecated(forRemoval = true, since = "TODO"), if applicable.
    • N/A - No deprecations added
  • UI changes do not introduce regressions when enforcing the current default rules of Content Security Policy Plugin. In particular, new or substantially changed JavaScript is not defined inline and does not call eval to ease future introduction of Content Security Policy (CSP) directives (see documentation).
    • Only changed response status check, no inline JS or eval
  • For dependency updates, there are links to external changelogs and, if possible, full differentials.
    • N/A - No dependency updates
  • For new APIs and extension points, there is a link to at least one consumer.
    • N/A - No new APIs added

Desired reviewers

@mawinter69 @timja @daniel-beck

@comment-ops-bot comment-ops-bot bot added the bug For changelog: Minor bug. Will be listed after features label Jan 13, 2026
@MarkEWaite MarkEWaite requested a review from Copilot January 13, 2026 12:58
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a bug where disabled multibranch projects incorrectly showed a "Build Scheduled" notification when users attempted to trigger builds on branch jobs, even though the builds were not actually scheduled.

Changes:

  • Modified isBuildable() to check if parent item (e.g., multibranch project) is disabled
  • Updated doBuild() to return 409 CONFLICT instead of redirect when build scheduling fails
  • Changed JavaScript response validation from rsp.ok to rsp.status === 201 for precise success detection

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
core/src/main/java/jenkins/model/ParameterizedJobMixIn.java Added parent disabled check to isBuildable() and changed failed build response from redirect to 409 CONFLICT
core/src/main/resources/lib/hudson/project/configurable/configurable.js Changed success detection from rsp.ok to explicit 201 status check
src/main/js/components/dropdowns/utils.js Added defensive null check for subMenu (unclear relationship to PR purpose)
src/main/js/components/dropdowns/jumplists.js Added null/array validation and subMenu safety checks (unclear relationship to PR purpose)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

menuItem,
Object.assign({}, Templates.dropdown(), {
content: generateDropdownItems(item.subMenu()),
content: generateDropdownItems(item.subMenu() || []),
Copy link

Copilot AI Jan 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes to this file (adding null/undefined checks for subMenu) don't appear to be related to the stated purpose of this PR, which is to fix disabled multibranch build notification. These defensive programming improvements should either be explained in the PR description or submitted as a separate PR to maintain clear change tracking and easier code review.

Copilot uses AI. Check for mistakes.
ItemGroup<? extends Item> parentGroup = ((Job) this).getParent();
if (parentGroup instanceof Item) {
Item parent = (Item) parentGroup;
if (parent instanceof ParameterizedJob && ((ParameterizedJob) parent).isDisabled()) {
Copy link

Copilot AI Jan 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The instanceof check for ParameterizedJob without a rawtype cast warning suppression may cause compilation warnings. Since ParameterizedJob is a generic interface, consider using a rawtype check or adding appropriate type safety annotations. Additionally, this check only verifies the immediate parent - consider whether checking all ancestors in the hierarchy would be more robust, or add a comment explaining why only the immediate parent is checked.

Suggested change
if (parent instanceof ParameterizedJob && ((ParameterizedJob) parent).isDisabled()) {
// Only the immediate parent is checked; higher-level ancestors are not modeled here.
if (parent instanceof ParameterizedJob<?,?> && ((ParameterizedJob<?,?>) parent).isDisabled()) {

Copilot uses AI. Check for mistakes.
Comment on lines 565 to +577
default boolean isBuildable() {
return !isDisabled() && !((Job) this).isHoldOffBuildUntilSave();
if (isDisabled() || ((Job) this).isHoldOffBuildUntilSave()) {
return false;
}
ItemGroup<? extends Item> parentGroup = ((Job) this).getParent();
if (parentGroup instanceof Item) {
Item parent = (Item) parentGroup;
if (parent instanceof ParameterizedJob && ((ParameterizedJob) parent).isDisabled()) {
return false;
}
}
return true;
Copy link

Copilot AI Jan 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding an automated test for the new behavior where a job with a disabled parent (e.g., multibranch project) is not buildable. The existing ParameterizedJobMixInTest.java already has tests for disabled projects, and a similar test could be added to verify the fix for disabled parent projects. This would provide regression protection for this specific bug fix.

Copilot uses AI. Check for mistakes.
…isabled

When trying to trigger a build of a branch job in a disabled multibranch
project, the UI showed 'Build Scheduled' even though the build was not
actually scheduled (queue returned null, causing a 302 redirect).

Changes:
- Updated isBuildable() to check if parent ParameterizedJob is disabled
- Changed doBuild() to return 409 CONFLICT when schedule2() returns null
- Fixed JavaScript to only treat HTTP 201 as success (not 302 redirects)

Fixes issue where disabled multibranch parent allows branch builds to
appear scheduled when they are actually rejected.
@LakshyaBagani LakshyaBagani force-pushed the fix-disabled-multibranch-build-notification branch from 56c1ee4 to 29371cc Compare January 13, 2026 16:27
@LakshyaBagani
Copy link
Contributor Author

Hi @Copilot AI,

Thanks for the review. I removed the changes to src/main/js/components/dropdowns/jumplists.js and src/main/js/components/dropdowns/utils.js from this PR.

Why they were included:
This branch was created from the Empty-list-in-menus-lead-to-endless-spinner branch, which included those defensive programming changes. I should have created this branch from master instead.

Why they were removed:
Those changes are unrelated to this PR (fixing the disabled multibranch build notification). They belong to a separate PR about fixing endless spinners in empty dropdown submenus.

Current state:
The PR now only includes the two files relevant to this fix:

  • core/src/main/java/jenkins/model/ParameterizedJobMixIn.java
  • core/src/main/resources/lib/hudson/project/configurable/configurable.js

@LakshyaBagani LakshyaBagani deleted the fix-disabled-multibranch-build-notification branch January 14, 2026 00:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug For changelog: Minor bug. Will be listed after features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[JENKINS-75417] Scheduling build under disabled Multibranch folder says "Build Scheduled" while it is not scheduled

2 participants