简体   繁体   English

Jenkins:从Active Choices参数groovy脚本访问其他插件

[英]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.

相关问题 Jenkins 声明式管道:如何从“主动选择反应引用参数的 Groovy 脚本”调用函数? - Jenkins Declarative Pipeline: How to call functions from "Active choices reactive reference parameter's Groovy script"? 如何从Jenkins中的Active Choices插件groovy脚本执行shell - How to execute shell from Active Choices Plugin groovy script in Jenkins Jenkins Groovy 和 Active Choices 反应参数 - Jenkins Groovy and Active Choices Reactive Parameter 如何在詹金斯的另一个活动选择参数的groovy脚本中读取活动选择参数的值? - how read active choices parameter value in another active chocices parameter's groovy script in jenkins? 在活动选择反应参数中使用groovy脚本 - Using groovy script in active choices reactive parameter 活动选择参数中的通用 Groovy 脚本 - Common Groovy script in active choices parameter 詹金斯:Active Choices参数+ Groovy基于REST响应对象构建列表 - Jenkins: Active Choices Parameter + Groovy to build a list based on REST responde Jenkins 在 groovy 脚本中检索活动选择参数 - Jenkins retrieve active choice parameter in groovy script 从Groovy脚本访问Jenkins插件包 - Accessing a Jenkins plugin package from a Groovy script 从Jenkins Groovy脚本访问GitLab JSON - Accessing GitLab JSON from Jenkins Groovy script
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM