sou*_*n.c 1 groovy jenkins jenkins-plugins
我希望显示的目录名(不是绝对路径)的詹金斯服务器的/ tmp目录在詹金斯下拉使用目录Active choice Reactive parameter Plugin。
我已经使用下面的代码显示了它。但它在输出中与其路径一起显示。
例如输出:
/tmp/directory1
/tmp/directory2
我需要输出为 :( 没有目录路径)
目录 1
目录 2
“主动选择反应参数插件”的groovy脚本部分使用的代码
import groovy.io.FileType
def list = []
def dir = new File("/tmp/")
dir.eachFileRecurse (FileType.FILES) { file ->
list << file
}
list.each {
println it.path
}
Run Code Online (Sandbox Code Playgroud)
干得好:
使用DIRECTORIES代替FILES
import static groovy.io.FileType.DIRECTORIES
def list = []
new File('/tmp').eachFileRecurse (DIRECTORIES) { file ->
list << file.name
}
return list
Run Code Online (Sandbox Code Playgroud)
如果您不需要递归,只需使用eachFile代替eachFileRecurse。
编辑:根据 OP 的评论,使用return list而不是print list作为上述脚本中的最后一条语句在 jenkins 中显示列表。
| 归档时间: |
|
| 查看次数: |
4215 次 |
| 最近记录: |