Skip to content

Commit 396e6e9

Browse files
authored
Hide build buttons in Multibranch branch/PR jobs when the Multibranch or organization folder is disabled (#26131)
1 parent 70f104b commit 396e6e9

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

core/src/main/java/hudson/model/Build.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
*
8484
* @author Kohsuke Kawaguchi
8585
*/
86-
public abstract class Build<P extends Project<P, B>, B extends Build<P, B>>
86+
public abstract class Build<P extends Project<P, B>, B extends Build<P, B>>
8787
extends AbstractBuild<P, B> {
8888

8989
/**

core/src/main/java/hudson/model/BuildableItem.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,14 @@ default boolean scheduleBuild(int quietPeriod) {
5757
}
5858

5959
boolean scheduleBuild(int quietPeriod, Cause c);
60+
61+
/**
62+
* Whether the item is buildable.
63+
*
64+
* @return true, if the item can be built.
65+
* @since TODO
66+
*/
67+
default boolean isBuildable() {
68+
return true;
69+
}
6070
}

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

Lines changed: 11 additions & 1 deletion
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;
@@ -562,8 +563,17 @@ default RunT createExecutable() throws IOException {
562563
return null;
563564
}
564565

566+
@Override
565567
default boolean isBuildable() {
566-
return !isDisabled() && !((Job) this).isHoldOffBuildUntilSave();
568+
if (isDisabled() || ((Job) this).isHoldOffBuildUntilSave()) {
569+
return false;
570+
}
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 BuildableItem bi) {
574+
return bi.isBuildable();
575+
}
576+
return true;
567577
}
568578

569579
@Extension

0 commit comments

Comments
 (0)