forked from electric-cloud/DSL-Samples
-
Notifications
You must be signed in to change notification settings - Fork 6
/
InstallFlowPlugins.groovy
69 lines (56 loc) · 1.87 KB
/
InstallFlowPlugins.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
/*
CloudBees Flow DSL: Install Plugins from PluginsToInstall list below
ectool evalDsl --dslFile InstallFlowPlugins.groovy --parameters '{"FlowUrl":"https://flow.example.com"}'
Where flow.example.com is the actual Flow URL
*/
import groovy.util.XmlParser
def PluginsToInstall = [
"unplug",
"EC-AuditReports",
"EC-DSLIDE",
"EC-Slack"
]
def FlowUrl = args.FlowUrl
// Get currently installed and promoted plugins
def InstalledPlugins = []
def PromotedPlugins = []
getPlugins().each { Plugin ->
InstalledPlugins.push(Plugin.pluginKey)
if (Plugin.promoted) {
PromotedPlugins.push(Plugin.pluginName)
}
}
// Get list of target plugins that aren't installed
def PluginsToInstallPruned = []
PluginsToInstall.each { PluginToInstall ->
if (! (PluginToInstall in InstalledPlugins)) {
PluginsToInstallPruned.push(PluginToInstall)
}
}
// Get Catalog details
def CatalogUrl = getProperty("/myProject/catalogUrl", pluginName: "EC-PluginManager").value
def CatalogXml = new URL(CatalogUrl).getText()
def plugins = new XmlParser().parseText(CatalogXml)
// Create procedure to install and promote plugins
project "Default", {
procedure "Install Plugins", {
PluginsToInstallPruned.each { Plugin ->
def version
def url
plugins.plugin.each { plugin ->
if (plugin["pluginName"].text()==Plugin) {
version = plugin["pluginVersion"].text()
url = plugin["downloadUrl"].text()
return true // break out of the loop
}
}
println "Creating steps to install ${Plugin}"
step "Install ${Plugin}",
command : "ectool installPlugin ${url}"
step "Promote ${Plugin}",
command: "ectool promotePlugin ${Plugin}-${version} --promoted 1"
}
}
}
def JobId = runProcedure(projectName: "Default", procedureName: "Install Plugins").jobId
println "Install Plugin Job: ${FlowUrl}/commander/link/jobDetails/jobs/${JobId}"