-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdefault-project-authorization.groovy
30 lines (23 loc) · 1.08 KB
/
default-project-authorization.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!groovy
import jenkins.model.Jenkins
import org.jenkinsci.plugins.authorizeproject.*
import org.jenkinsci.plugins.authorizeproject.strategy.*
import jenkins.security.QueueItemAuthenticatorConfiguration
def jenkins = Jenkins.getInstance()
// Define which strategies you want to allow to be set per project
def strategyMap = [
(jenkins.getDescriptor(AnonymousAuthorizationStrategy.class).getId()): true,
(jenkins.getDescriptor(TriggeringUsersAuthorizationStrategy.class).getId()): true,
(jenkins.getDescriptor(SpecificUsersAuthorizationStrategy.class).getId()): true,
(jenkins.getDescriptor(SystemAuthorizationStrategy.class).getId()): false
]
def authenticators = QueueItemAuthenticatorConfiguration.get().getAuthenticators()
def configureProjectAuthenticator = true
// only add if it does not already exist
for (authenticator in authenticators) {
if (authenticator instanceof ProjectQueueItemAuthenticator)
configureProjectAuthenticator = false
}
if (configureProjectAuthenticator)
authenticators.add(new ProjectQueueItemAuthenticator(strategyMap))
jenkins.save()