-
Notifications
You must be signed in to change notification settings - Fork 11
/
AC_RefHelper_getSelectArtifactUrl.groovy
57 lines (53 loc) · 1.55 KB
/
AC_RefHelper_getSelectArtifactUrl.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
/*** BEGIN META {
"name" : "AC_RefHelper_getSelectArtifactUrl",
"comment" : "Returns a comma separated list of artifact URLs that contains/startsWith/endsWith the 'selector' string as input HTML",
"parameters" : [ 'vBuildRef','vSelector','vSelectLogic'],
"core": "1.593",
"authors" : [
{ name : "Ioannis Moutsatsos" }
]
} END META**/
import hudson.model.*
/*
for backward compatibility we set 'contains' as the default
if selectLogic parameter is not provided
*/
String selectLogic
if (binding.variables.containsKey("vSelectLogic")){
selectLogic=vSelectLogic
}
if(selectLogic==null || selectLogic==''){
selectLogic='contains'
}
def choices=[]
def project=vBuildRef.split('#')[0]
def buildNo=vBuildRef.split('#')[1]
def job = hudson.model.Hudson.instance.getItem(project)
def build=job.getBuildByNumber(buildNo.toInteger())
selector=vSelector
env=[:]
env= build.getEnvironment(TaskListener.NULL);
buildURL=env['BUILD_URL']
artifact=[]
artifact= build.getArtifacts()
artifact.each{
switch(selectLogic){
case"contains":
if((it as String).contains(selector)){
choices.add("${buildURL}artifact/$it")
}//end if contains
break
case"startsWith":
if((it as String).startsWith(selector)){
choices.add("${buildURL}artifact/$it")
}//end if startsWith
break
case"endsWith":
if((it as String).endsWith(selector)){
choices.add("${buildURL}artifact/$it")
}//end if endsWith
break
}
}
theValue=choices.join(',')
return '<input name="value" value="'+theValue+'" class="setting-input" type="text">'