Is there any way to list latest Nexus Artifacts in Jenkins?

和自甴很熟 提交于 2020-12-07 08:10:12

问题


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?


回答1:


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

Jenkins snapshot

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()


来源:https://stackoverflow.com/questions/62547865/is-there-any-way-to-list-latest-nexus-artifacts-in-jenkins

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!