问题
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