Skip to content

Commit 7025455

Browse files
committed
Fix false 'Build Scheduled' notification when parent multibranch is disabled
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.
1 parent 1366fa9 commit 7025455

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

core/src/main/java/jenkins/model/ParameterizedJobMixIn.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import hudson.model.Cause;
4141
import hudson.model.CauseAction;
4242
import hudson.model.Item;
43+
import hudson.model.ItemGroup;
4344
import hudson.model.Items;
4445
import hudson.model.Job;
4546
import hudson.model.ParameterDefinition;
@@ -231,7 +232,7 @@ public final void doBuild(StaplerRequest2 req, StaplerResponse2 rsp, @QueryParam
231232
// TODO JENKINS-66105 use SC_SEE_OTHER if !ScheduleResult.created
232233
rsp.sendRedirect(SC_CREATED, req.getContextPath() + '/' + item.getUrl());
233234
} else {
234-
rsp.sendRedirect(".");
235+
throw HttpResponses.errorWithoutStack(SC_CONFLICT, asJob().getFullName() + " is not buildable");
235236
}
236237
}
237238

@@ -563,7 +564,19 @@ default RunT createExecutable() throws IOException {
563564
}
564565

565566
default boolean isBuildable() {
566-
return !isDisabled() && !((Job) this).isHoldOffBuildUntilSave();
567+
if (isDisabled() || ((Job) this).isHoldOffBuildUntilSave()) {
568+
return false;
569+
}
570+
// Check if parent (e.g., multibranch project) is disabled
571+
// If parent is disabled, child jobs (e.g., branch jobs) should not be buildable
572+
ItemGroup<? extends Item> parentGroup = ((Job) this).getParent();
573+
if (parentGroup instanceof Item) {
574+
Item parent = (Item) parentGroup;
575+
if (parent instanceof ParameterizedJob && ((ParameterizedJob) parent).isDisabled()) {
576+
return false;
577+
}
578+
}
579+
return true;
567580
}
568581

569582
@Extension

core/src/main/resources/lib/hudson/project/configurable/configurable.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
method: "post",
1111
headers: crumb.wrap({}),
1212
}).then((rsp) => {
13-
if (rsp.ok) {
13+
if (rsp.status === 201) {
1414
notificationBar.show(success, notificationBar.SUCCESS);
1515
} else {
1616
notificationBar.show(failure, notificationBar.ERROR);

0 commit comments

Comments
 (0)