diff --git a/vars/addVersionFromNexusRepo.groovy b/vars/addVersionFromNexusRepo.groovy index bef9320..066d6bb 100644 --- a/vars/addVersionFromNexusRepo.groovy +++ b/vars/addVersionFromNexusRepo.groovy @@ -36,17 +36,20 @@ Map call(Map config = [:], Map queryParams = [:]) { body = response.content assets = readJSON text: body latest = assets.items.last() - version = latest.version - build = 0 - buildNumFromQuery = '1' - if ((latest.version ?: null) == null) { - matches = (latest.name =~ /.*-([0-9\.]+)-([0-9]+)\.)[0]/)[0] - version = matches[1] - build = matches[2] + version = latest.version ?: (latest.name =~ /.*-([0-9\.]+)-([0-9]+)\..*/)[0][1] + build = latest.version ?: (latest.name =~ /.*-([0-9\.]+)-([0-9]+)\..*/)[0][2] + + if (version == null) { + // Call the error method and pass a string indicating version was null and name is not parseable + error('Version was null and name is not parseable') } - runConfig.nexusQuery = nexusSearch - runConfig.latestVersion = version - runConfig.latestBuild = build + + if (build == null) { + unstable("Build number could not be found in latest asset match (${latest.name})") + } + build = build ?: env.BUILD_NUMBER + runConfig.version = version + runConfig.build = build return runConfig }