-
Notifications
You must be signed in to change notification settings - Fork 1
/
configure-plugin-jira.groovy
50 lines (44 loc) · 1.51 KB
/
configure-plugin-jira.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Setting up Jira
import jenkins.model.*
import jenkins.*
import hudson.model.*
import hudson.*
import net.sf.json.JSONArray
import net.sf.json.JSONObject
import org.thoughtslive.jenkins.plugins.jira.Config
import org.thoughtslive.jenkins.plugins.jira.Site
//global user-defined configuration
JSONArray sites = [
[
name: 'Jira',
url: 'http://jira:8080',
timeout: 10000,
loginType: 'BASIC',
userName: 'jira',
password: 'jira'
]
] as JSONArray
//get global Jenkins configuration
Config.ConfigDescriptorImpl config = Jenkins.instance.getExtensionList(Config.ConfigDescriptorImpl.class)[0]
//delete all existing sites
//configure new sites from the above JSONArray
sites.each { s ->
String loginType = s.optString('loginType', '').toUpperCase()
if(loginType in ['BASIC', 'OAUTH']) {
Site site = new Site(s.optString('name',''), new URL(s.optString('url', '')), s.optString('loginType', ''), s.optInt('timeout', 10000))
if(loginType == 'BASIC') {
site.setUserName(s.optString('userName', ''))
site.setPassword(s.optString('password', ''))
} else { //loginType is OAUTH
site.setConsumerKey(s.optString('consumerKey', ''))
site.setPrivateKey(s.optString('privateKey', ''))
site.setSecret(s.optString('secret', ''))
site.setToken(s.optString('token', ''))
}
//setSites does not make sense as a name because you can only set one site instead of a list :-/
config.setSites(site)
}
}
//persist configuration to disk as XML
config.save()