Skip to content

Commit f704153

Browse files
authored
Add option to specify root folder for the organisation (#2662)
* Add option to specify root folder for the organisation
1 parent ac25eac commit f704153

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

blueocean-rest-impl/src/main/java/io/jenkins/blueocean/service/embedded/OrganizationFactoryImpl.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
import java.util.Collection;
1212
import java.util.Collections;
13+
import java.util.logging.Level;
14+
import java.util.logging.Logger;
1315

1416
/**
1517
* Default implementation of {@link OrganizationFactory} for a controller is to have everything in
@@ -22,6 +24,10 @@ public class OrganizationFactoryImpl extends OrganizationFactory {
2224
private static final String ORGANIZATION_NAME = StringUtils.defaultIfBlank(
2325
System.getProperty("BLUE_ORGANIZATION_NAME"),"jenkins");
2426

27+
private static final String ROOT_FOLDER_NAME = System.getProperty("BLUE_ORGANIZATION_ROOT_FOLDER");
28+
29+
private static final Logger LOG = Logger.getLogger(OrganizationFactoryImpl.class.getName());
30+
2531
/**
2632
* In embedded mode, there's only one organization
2733
*/
@@ -32,7 +38,17 @@ public OrganizationFactoryImpl() {
3238
}
3339

3440
public OrganizationFactoryImpl(String name) {
35-
this.instance = new OrganizationImpl(name, Jenkins.get());
41+
if (ROOT_FOLDER_NAME != null) {
42+
var root = Jenkins.get().getItemByFullName(ROOT_FOLDER_NAME);
43+
if (root instanceof ItemGroup<?> group) {
44+
this.instance = new OrganizationImpl(name, group);
45+
} else {
46+
LOG.warning(() -> "Specified BLUE_ORGANIZATION_ROOT_FOLDER '" + ROOT_FOLDER_NAME + "' not found, or not a Folder. Falling back to Jenkins root folder.");
47+
this.instance = new OrganizationImpl(name, Jenkins.get());
48+
}
49+
} else {
50+
this.instance = new OrganizationImpl(name, Jenkins.get());
51+
}
3652
}
3753

3854
@Override

0 commit comments

Comments
 (0)