Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions src/main/java/jenkins/branch/MultiBranchProject.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,13 @@

private static /* not final */ boolean FIRE_SCM_SOURCE_BUILDS_AFTER_SAVE =
SystemProperties.getBoolean(MultiBranchProject.class.getName() + ".fireSCMSourceBuildsAfterSave", true);

/**
* Maximum concurrent indexing.
* Can be configured via system property jenkins.branch.MultiBranchProject.maxConcurrentIndexing
*/
private static final int MAX_CONCURRENT_INDEXING =
SystemProperties.getInteger(MultiBranchProject.class.getName() + ".maxConcurrentIndexing", 5);

/**
* Our logger.
Expand Down Expand Up @@ -905,6 +912,15 @@
public synchronized BranchIndexing<P, R> getIndexing() {
return (BranchIndexing) getComputation();
}

/**
* Returns the maximum concurrent indexing limit.
*
* @return the maximum concurrent indexing limit
*/
public static int getMaxConcurrentIndexing() {
return MAX_CONCURRENT_INDEXING;

Check warning on line 922 in src/main/java/jenkins/branch/MultiBranchProject.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 922 is not covered by tests
}

/**
* {@inheritDoc}
Expand Down Expand Up @@ -1082,6 +1098,35 @@
}
return super.isBuildable() && !sources.isEmpty();
}

/**
* {@inheritDoc}
*/
@Override
public hudson.model.queue.CauseOfBlockage getCauseOfBlockage() {
// Check if we've exceeded the maximum concurrent indexing limit
if (indexingCount() > MAX_CONCURRENT_INDEXING) {

Check warning on line 1108 in src/main/java/jenkins/branch/MultiBranchProject.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 1108 is only partially covered, one branch is missing
return hudson.model.queue.CauseOfBlockage.fromMessage(
Messages._MultiBranchProject_MaxConcurrentIndexing(MAX_CONCURRENT_INDEXING)

Check warning on line 1110 in src/main/java/jenkins/branch/MultiBranchProject.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 1109-1110 are not covered by tests
);
}
return super.getCauseOfBlockage();
}

/**
* Count the number of multibranch projects currently indexing.
*
* @return the number of projects currently indexing
*/
private static int indexingCount() {
int count = 0;
for (MultiBranchProject<?, ?> project : Jenkins.get().getAllItems(MultiBranchProject.class)) {
if (project.getComputation() != null && project.getComputation().isBuilding()) {

Check warning on line 1124 in src/main/java/jenkins/branch/MultiBranchProject.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 1124 is only partially covered, one branch is missing
count++;
}
}
return count;
}

/**
* {@inheritDoc}
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/jenkins/branch/Messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ RateLimitBranchProperty.duration.month=Month
RateLimitBranchProperty.duration.year=Year
MultiBranchProject.BranchIndexing.displayName=Scan {0}
MultiBranchProject.CopyItemVeto.reason=Copying branch projects outside of their multi-branch container is not supported.
MultiBranchProject.MaxConcurrentIndexing=Already indexing maximum number of projects (limit: {0})
MultiBranchProjectDisplayNamingTrait.DisplayName=Job display name with fallback to name
MultiBranchProjectDisplayNamingTrait.Raw=Simple name only
MultiBranchProjectDisplayNamingTrait.RawAndDisplayName=Name and, if available, display name
Expand Down