问题描述
我知道动态参数和动态扩展选项参数插件。我正在寻找一种方法,将github中目录中的文本文件列为下拉列表参数。是否有一个groovy脚本或类似的,可以用文件名填充下拉菜单? 您可以使用来获取给定回购商给定路径的文件列表。例如,要查看 ratpack-groovy / src / main / java / ratpack / groovy
,你可以这样做:
import groovy.json。*
def contents = new JsonSlurper().parse('https://api.github.com/repos/ratpack/ratpack/contents/ratpack- groovy / src / main / java / ratpack / groovy'.toURL())
.sort {it.type} //目录首先
.collect {it.name +(it.type ==' dir'?'/':'')} //放一个斜线在目录的末尾
assert contents = ['处理/',
'内部/',
'渲染/',
'脚本/',
'server /',
'sql /',
'template /',
'Groovy.java',
'GroovyRatpackMain.java',
'package-info.java']
显然你只能使
I'm aware of the Dynamic Parameter and Dynamic Extended Choice Parameter plugins. I'm looking for a way to list of text files in a directory in github as drop down list parameter. is there a groovy script or similar that can populate the dropdown with file names?
You can use the github api to fetch a list of files for a given path on a given repo.
So for example, to look inside the ratpack-groovy/src/main/java/ratpack/groovy
folder of the ratpack project on github, you can do:
import groovy.json.*
def contents = new JsonSlurper().parse('https://api.github.com/repos/ratpack/ratpack/contents/ratpack-groovy/src/main/java/ratpack/groovy'.toURL())
.sort { it.type } // Directories first
.collect { it.name + (it.type == 'dir' ? '/' : '') } // Put a slash on the end of directories
assert contents = ['handling/',
'internal/',
'render/',
'script/',
'server/',
'sql/',
'template/',
'Groovy.java',
'GroovyRatpackMain.java',
'package-info.java']
Obviously you can only make 60 requests per hour
这篇关于使用Github目录文件动态填充Jenkins作业参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!