-
Notifications
You must be signed in to change notification settings - Fork 18
/
github-oauth.groovy.disabled
68 lines (58 loc) · 2.69 KB
/
github-oauth.groovy.disabled
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// GitHub OAuth settings
// Create an app at https://github.com/settings/applications/new
// The GitHub Authorization callback URL should be (add a prefix if necessary)
// https://hostname/securityRealm/finishLogin
// GitHub client ID
String clientID = 'someid'
// GitHub client secret
String clientSecret = 'somesecret'
// GitHub OAuth scopes
String oauthScopes = 'read:org'
// List of GitHub users who are Jenkins admins
String adminUserNames = 'microscopepony,snoopycrimecop'
// Allow access to members of this GitHub organisation
String organizationNames = 'ome'
// Permissions: you probably don't need to change these
// Use GitHub repository permissions
boolean useRepositoryPermissions = false
// Grant READ permissions to all Authenticated Users
boolean authenticatedUserReadPermission = false
// Grant CREATE Job permissions to all Authenticated Users
boolean authenticatedUserCreateJobPermission = false
// Grant READ permissions for /github-webhook
boolean allowGithubWebHookPermission = true
// Grant READ permissions for /cc.xml
boolean allowCcTrayPermission = true
// Grant READ permissions for Anonymous Users
boolean allowAnonymousReadPermission = true
// Grant ViewStatus permissions for Anonymous Users
boolean allowAnonymousJobStatusPermission = true
// ************************************************************************* //
// https://wiki.jenkins.io/display/JENKINS/GitHub+OAuth+Plugin#GitHubOAuthPlugin-Automaticallyconfiguresecurityrealmviascriptconsole
import jenkins.model.Jenkins
import hudson.security.SecurityRealm
import org.jenkinsci.plugins.GithubSecurityRealm
String githubWebUri = 'https://github.com'
String githubApiUri = 'https://api.github.com'
SecurityRealm github_realm = new GithubSecurityRealm(githubWebUri, githubApiUri, clientID, clientSecret, oauthScopes)
//check for equality, no need to modify the runtime if no settings changed
if(!github_realm.equals(Jenkins.instance.getSecurityRealm())) {
Jenkins.instance.setSecurityRealm(github_realm)
Jenkins.instance.save()
}
import org.jenkinsci.plugins.GithubAuthorizationStrategy
import hudson.security.AuthorizationStrategy
AuthorizationStrategy github_authorization = new GithubAuthorizationStrategy(adminUserNames,
authenticatedUserReadPermission,
useRepositoryPermissions,
authenticatedUserCreateJobPermission,
organizationNames,
allowGithubWebHookPermission,
allowCcTrayPermission,
allowAnonymousReadPermission,
allowAnonymousJobStatusPermission)
//check for equality, no need to modify the runtime if no settings changed
if(!github_authorization.equals(Jenkins.instance.getAuthorizationStrategy())) {
Jenkins.instance.setAuthorizationStrategy(github_authorization)
Jenkins.instance.save()
}