有什么办法可以列出詹金斯(Jenkins)的最新Nexus工件? [英] Is there any way to list latest Nexus Artifacts in Jenkins?

查看:219
本文介绍了有什么办法可以列出詹金斯(Jenkins)的最新Nexus工件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Acive Choice反应参数插件列出Nexus Artifacts.这是我当前正在使用的groovy脚本.

I am using Acive Choice Reactive Parameter plugin to list down Nexus Artifacts. This is the groovy script which I'm currently using.

import groovy.json.*

def targetUrl = "https://nexus.xxxx.lk/service/rest/v1/search?repository=snapshots&format=maven2&group=com.org.pro&name=pro-service"
def jsonSlupper = new JsonSlurper().parse(URI.create(targetUrl).toURL())
def list = jsonSlupper["items"]["version"].collect().sort().reverse()

我只想在列表中显示最新的工件.有谁知道该怎么做?

I want to display only latest artifact in the list. Does anyone know, how to do this?

推荐答案

我们可以使用元数据API,您可以同时使用快照回购或发布回购或公共回传,仅限制最后5个版本.

we can use metadata API, you can use snapshots repo or release repo or public for both, just limit the last 5 versions.

Jenkins快照

def host="https://msnexus.xxx.com"
def groupId="com.xxx.cd".replaceAll("\\.", "/")
def artifactId="common-log"
def nexus_url="${host}/repository/public/${groupId}/${artifactId}/maven-metadata.xml"
def response=nexus_url.toURL().text
def metadata = new XmlParser().parseText(response)

metadata.versioning.versions.version.takeRight(5).collect({it.text()}).reverse()

这篇关于有什么办法可以列出詹金斯(Jenkins)的最新Nexus工件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆