Switch API to use find rather than add.
This commit is contained in:
parent
96ee3f0051
commit
1d416ce821
@ -26,6 +26,9 @@ Map call(Map config = [:], Map queryParams = [:]) {
|
|||||||
Map runConfig = defaults + config
|
Map runConfig = defaults + config
|
||||||
Map query = queryParamsDefaults + queryParams
|
Map query = queryParamsDefaults + queryParams
|
||||||
|
|
||||||
|
def version
|
||||||
|
def response
|
||||||
|
|
||||||
nexusURL = runConfig.nexusBase + '/' + runConfig.searchAPI
|
nexusURL = runConfig.nexusBase + '/' + runConfig.searchAPI
|
||||||
nexusSearch = buildUrlWithQueryParams(nexusURL, query)
|
nexusSearch = buildUrlWithQueryParams(nexusURL, query)
|
||||||
|
|
||||||
@ -33,24 +36,32 @@ Map call(Map config = [:], Map queryParams = [:]) {
|
|||||||
contentType: 'APPLICATION_JSON',
|
contentType: 'APPLICATION_JSON',
|
||||||
url: nexusSearch,
|
url: nexusSearch,
|
||||||
wrapAsMultipart: false
|
wrapAsMultipart: false
|
||||||
|
|
||||||
|
|
||||||
body = response.content
|
body = response.content
|
||||||
assets = readJSON text: body
|
assets = readJSON text: body
|
||||||
|
if (assets.items && !assets.items.isEmpty()) {
|
||||||
latest = assets.items.last()
|
latest = assets.items.last()
|
||||||
version = latest.version ?: (latest.name =~ /.*-([0-9\.]+)-([0-9]+)\..*/)[0][1]
|
/* We have to use instanceof here. The value SHOULD be null, but it comes back
|
||||||
build = latest.version ?: (latest.name =~ /.*-([0-9\.]+)-([0-9]+)\..*/)[0][2]
|
as class rather than null. This is probably a bug in the Pipeline Utilities
|
||||||
|
plugin. */
|
||||||
if (version == null) {
|
/* groovylint-disable-next-line Instanceof */
|
||||||
// Call the error method and pass a string indicating version was null and name is not parseable
|
if (latest.version instanceof net.sf.json.JSONNull && latest.name) {
|
||||||
error('Version was null and name is not parseable')
|
echo "Search result version field was null, looking in name field for a version"
|
||||||
|
def match = (latest.name =~ /(?<=-)([0-9\.]{1,3})(?:-|\.)[^-\.]+/)
|
||||||
|
if (!match) {
|
||||||
|
echo "Match: ${match}"
|
||||||
|
error("Regular expression match failed for latest.name: ${latest.name}")
|
||||||
}
|
}
|
||||||
|
version = match[0][1]
|
||||||
if (build == null) {
|
} else if (latest.version) {
|
||||||
unstable("Build number could not be found in latest asset match (${latest.name})")
|
version = latest.version
|
||||||
}
|
}
|
||||||
build = build ?: env.BUILD_NUMBER
|
} else {
|
||||||
runConfig.version = version
|
version = '0.0.1'
|
||||||
runConfig.build = build
|
unstable('No matching assets found, assuming this is the first version')
|
||||||
return runConfig
|
}
|
||||||
|
return version
|
||||||
}
|
}
|
||||||
|
|
||||||
/* groovylint-disable-next-line MethodParameterTypeRequired, NoDef */
|
/* groovylint-disable-next-line MethodParameterTypeRequired, NoDef */
|
||||||
Loading…
Reference in New Issue
Block a user