-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjenkins_select_build.groovy
84 lines (74 loc) · 2.05 KB
/
jenkins_select_build.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
@Grab(group='org.jsoup', module='jsoup', version='1.7.3')
import org.jsoup.Jsoup;
import org.boon.Boon;
def doc = Jsoup.connect('http://example.com/dir/list/').get()
def versions = []
doc.select("pre > a").each{href ->
def filename = href.text()
if(filename.endsWith("/") && filename != "../") {
versions.add('"' + filename.substring(0, filename.length()-1) + '"')
}
}
versions.sort(true) { a,b ->
a = a.replace("\"", "")
b = b.replace("\"", "")
List verA = a.tokenize('.')
List verB = b.tokenize('.')
def commonIndices = Math.min(verA.size(), verB.size())
for (int i = 0; i < commonIndices; ++i) {
def numA = verA[i].toInteger()
def numB = verB[i].toInteger()
// println "comparing $numA and $numB"
if (numA != numB) {
return numA <=> numB
}
}
// If we got this far then all the common indices are identical, so whichever version is longer must be more recent
verA.size() <=> verB.size()
}.reverse(true)
def form_properties = /
disable_edit_json: true,
disable_properties: true,
no_additional_properties: true,
disable_collapse: false,
disable_array_add: false,
disable_array_delete: false,
disable_array_reorder: false,
theme: "bootstrap2",
iconlib:"fontawesome3"
/;
def form_body = /
"title": "Deploy",
"type": "object",
"properties": {
"versions": {
"type": "array",
"format": "table",
"title": "Versions",
"uniqueItems": true,
"items": {
"type": "object",
"title": "version",
"properties": {
"version": {
"type": "string",
"enum": [ / + versions.join(", ") + / ],
"default": / + versions[0] + /
},
"percent": {
"type": "integer",
"default": 100
}
}
},
"default": [
{
"version": / + versions[0] + /,
"percent": 100
}
]
}
}
/;
def jsonEditorOptions = Boon.fromJson('{ ' + form_properties + ', "schema": {' + form_body + '} }');
return jsonEditorOptions;