[英]Jenkins: Accessing other plugins from Active Choices Parameter groovy script
I'm quite new to Jenkins, Groovy and all that, so forgive me if this sounds dumb. 我对詹金斯(Jenkins),Groovy以及所有这些都还很陌生,所以如果听起来很蠢,请原谅我。 I'm using the Active Choices plugin, and from one of the AC Parameters inside the Groovy script I want to use a different plugin - Artifactory, to fetch a file and display each line inside it as an option. 我正在使用Active Choices插件,并且从Groovy脚本中的AC参数之一中,我想使用其他插件-Artifactory来获取文件并显示其中的每一行作为选项。
try {
def server = Artifactory.newServer url: 'http://localhost:8081/artifactory/', username: 'user', password: 'pass'
def downloadSpec = """{
"files": [
{
"pattern": "example-repo-local/file.txt",
"target": "example/"
}
]
}"""
server.download(downloadSpec)
String text = readFile("example/file.txt")
return text.tokenize("\n")
} catch (Exception e) {
return [e]
}
However, the Active Choices Parameter doesn't seem to recognize other plugins, and it can't find the Artifactory property: 但是,Active Choices参数似乎无法识别其他插件,并且找不到Artifactory属性:
groovy.lang.MissingPropertyException: No such property: Artifactory for class: Script1
My question is - do I need to import the plugin somehow? 我的问题是-我需要以某种方式导入插件吗? If so, how do I determine what to import? 如果是这样,我如何确定要导入什么?
There is an option to also specify an "Additional classpath" near an Active Choice Parameter, but the plugin contains 75 jar files in its WEB-INF/lib directory. 还可以在Active Choice参数附近指定一个“附加类路径”,但该插件的WEB-INF / lib目录中包含75个jar文件。 (just specifying the artifactory.jar one doesn't seem to change anything) (仅指定artifactory.jar似乎并没有改变任何东西)
Just a note - the Pipeline recognizes the Artifactory plugin and it works fine - I can successfully connect and retreive a file and read it. 只需注意-管道可以识别Artifactory插件,并且效果很好-我可以成功连接并获取文件并读取它。
I can't fine any possibility to run Artifactory plugin in reasonable way. 我无法以合理的方式运行Artifactory插件。 So i thing better option is use curl, and Artifactory API . 所以我更好的选择是使用curl和Artifactory API 。 For example my Active Choices Parameter
based on Json file from Artifactory; 例如,我基于Artifactory的Json文件的Active Choices Parameter
;
import groovy.json.JsonSlurper
def choices = []
def response = ["curl", "-k", "https://artifactory/app/file.json"].execute().text
def list = new JsonSlurper().parseText( response )
list.each { choices.push(it.name) }
return choices
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.