【问题标题】:Jenkins and Nexus Repository Manager Choice ParameterJenkins 和 Nexus 存储库管理器选择参数
【发布时间】:2020-11-02 08:17:50
【问题描述】:

我知道 Jenkins 中有一个 Nexus 平台插件 https://plugins.jenkins.io/nexus-jenkins-plugin/,但我不确定以下是否可行,任何建议或建议将不胜感激。

在 Jenkins 中,您有 Git 选择参数,这允许您在工作中构建特定的标签/分支,Sonatype Nexus 有类似的东西吗?我们有一个内部链接,我们可以在其中上传和标记 docker 图像。

我目前有一份 Jenkins 工作,我必须手动输入图像版本。 Jenkins有没有办法获得一个选择参数,我可以在其中查询nexus中的所有标签。

例如我可以运行命令-> docker pull internal/application/service:0.0.1 因此开发人员会上传一个新版本,例如 0.0.2

来自 Jenkins,我想显示 0.0.1 或 0.0.2 的列表供支持团队构建。 不确定目前是否可行?

2020 年 7 月 15 日更新

我已经阅读了主动选择参数插件。这允许您执行一个 groovy 脚本。

所以我创建了以下

import groovy.json.JsonSlurper
// GET
try {
    def get = new URL("http://internalserver:8081/service/rest/v1/search?repository=docker-internal&name=application/service/moo").openConnection();
    def getRC = get.getResponseCode();
//println(getRC);
    if (getRC.equals(200)) {
        //println(get.getInputStream().getText());
        JsonSlurper slurper = new JsonSlurper()
        Map parsedJson = slurper.parseText(get.getInputStream().getText())
        tags = parsedJson.items.version
        //println(tags)
        def sorted_tags = []
        sorted_tags.push(tags)
        println(sorted_tags)
    }
}catch(Exception e){
    println(e)
}

如果我从我的 IDE 运行此代码,它会打印出标签,但如果我将它添加到活动选择插件,我的下拉菜单是空白的?

【问题讨论】:

标签: jenkins groovy jenkins-plugins sonatype


【解决方案1】:

好的,我让它工作了 Jenkins 组合框需要一个返回类型。 因此,如果有人想做类似的事情,那么下面对我有用。

<code>
import groovy.json.JsonSlurper
try {
    def get = new URL("http://yourinternalnexusurl:8018/applicacation/v1...etc").openConnection();
    def getRC = get.getResponseCode();
    if (getRC.equals(200)) {
        def nexus_response = [:]
        nexus_response = new JsonSlurper().parseText(get.getInputStream().getText())
        def image_tag_list = []
        for (tag in nexus_response.items.version){
            image_tag_list.add(tag)
        }
       return image_tag_list.sort()
    }
}catch(Exception e){
    println(e)
}
</code>

【讨论】:

    【解决方案2】:

    Maven Artifact ChoiceListProvider (Nexus) 可以满足您的要求。

    通过此扩展,可以使用来自 Maven 存储库(如 Nexus、Maven-Central 或 Artifactory)的服务 API 来使用 groupId、artifactId 和打包搜索工件。

    此插件将允许用户从存储库中的可用工件中选择一个版本,并将 URL 作为环境变量发布。插件将返回所选工件的完整 URL,以便在构建期间可用,即您可以使用“wget”检索工件 示例

    然后您可能必须解析(groovy ?)生成的 env 变量以作为您的参数提供。

    【讨论】:

    • 我会看看,但我认为那只是为了工件而不是标签,但会看看我能做什么非常感谢你的建议
    • 也许你可以提交一个issue 来扩展插件或贡献它和submit a PR
    猜你喜欢
    • 1970-01-01
    • 2017-08-19
    • 1970-01-01
    • 1970-01-01
    • 2010-10-17
    • 2012-07-13
    • 1970-01-01
    • 2021-10-24
    • 1970-01-01
    相关资源
    最近更新 更多