forked from electric-cloud/DSL-Samples
-
Notifications
You must be signed in to change notification settings - Fork 6
/
CreateFlowPluginConfigurations.groovy
95 lines (84 loc) · 2.77 KB
/
CreateFlowPluginConfigurations.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*
Create Flow Plugin configurations
Usage: ectool evalDsl --dslFile CreateFlowPluginConfigurations.groovy --parameters '{"PluginConfigFilePath":"PluginConfigs.json"}'
Where PluginConfigFilePath references a path on the Flow Server
PluginConfigs.json format:
[
{
"ConfigName": "A config name",
"PluginName": "EC-PluginName",
"Username": "a user",
"Password": "a password",
"Parameters": {
"aParam": "a parameter value",
"anotherParam": "Another param value"
}
},
{
"ConfigName": "Another config name",
"PluginName": "EC-PluginName2",
"Username": "another user",
"Password": "another password",
"Parameters": {
"bParam": "b parameter value",
"bnotherParam": "Bnother param value"
}
}
]
Where the parameter names come from the plugins's CreateConfiguration procedure
*/
import groovy.json.*
def PluginConfigFilePath = args.PluginConfigFilePath
def PluginConfigsJson = new File(PluginConfigFilePath).text
def jsonSlurper = new JsonSlurper()
def PluginConfigs = jsonSlurper.parseText(PluginConfigsJson)
PluginConfigs.each { conf ->
def proj="/plugins/${conf.PluginName}/project"
def confName = conf.ConfigName
def uName= conf.Username
def pwd= conf.Password
def ConfigPropertySheet = getProperty(propertyName: "ec_config/configLocation", projectName: proj).value
// Does ConfigPropertySheet property sheet exist?
def existsConfigPropertySheet = false
getProperties(projectName: proj).property.each {
if (it.propertyName==ConfigPropertySheet) {existsConfigPropertySheet=true}
}
// Create a list of existing configurations in this plugin project
def ExistingConfigs = []
if (existsConfigPropertySheet) {
getProperties(propertySheetId: getProperty(ConfigPropertySheet, projectName: proj).propertySheetId).property.each {
ExistingConfigs.push(it.name)
}
}
// Create a Transient credential
def Cred = new RuntimeCredentialImpl()
Cred.name = confName
Cred.userName = uName
Cred.password = pwd
def Creds=[Cred]
def Params = [ config:confName, basic_credential:confName ] + conf.Parameters
if (! (confName in ExistingConfigs)) {
// Create a new configuration by running the plugin create configuration procedure
runProcedure(
projectName : proj,
procedureName : "CreateConfiguration",
actualParameter : Params,
credential: Creds
)
} else {
/*
// Update the configuration
// overwrite the credential
credential(
projectName: proj,
userNane: uName
password: pwd
credentialName: confName
)
// overtrite properties
conf.Parameters.each { param, val ->
property "${ConfigPropertySheet}/${confName}/${param}", projectName: proj, value: val
}
*/
}
} // Each conf