【发布时间】:2020-03-29 23:05:52
【问题描述】:
我们使用 sonatype nexus OSS 3.14.0-04 来存储我们所有的工件,并使用 Jenkins 作为我们的 CI/CD 所用。我最近介绍了快照支持。在 Jenkins 中,我使用以下 groovy 脚本来获取所有工件版本并填充活动选择下拉列表:
#!/usr/bin/env groovy
import groovy.json.JsonSlurper
def source = "release"
def url = "http://<<nexus-host>>/service/rest/v1/search?repository=maven-releases&maven.groupId=com.xyz&maven.artifactId=woof&maven.extension=war"
Set<String> versions = new HashSet<>();
def continuationToken = null
def count = 0
def url1 = url
while (true) {
def xml = url1.toURL().text
JsonSlurper parser = new groovy.json.JsonSlurper()
Map parsedJson = parser.parseText(xml)
def rawVer = parsedJson.items.version
continuationToken = parsedJson.continuationToken
if (continuationToken != null) {
url1 = url + "&continuationToken=" + continuationToken
}
if (source.equalsIgnoreCase('snapshot')) {
Set<String> modVersion = new HashSet<>()
for (def item : rawVer) {
modVersion.add(item.split("-").getAt(0) + "-SNAPSHOT")
}
versions.addAll(modVersion)
} else {
versions.addAll(rawVer)
}
if (continuationToken == null || count > 5) {
break;
}
}
return versions.sort().reverse()
【问题讨论】:
标签: api groovy nexus sonatype nexus3