From 96ee3f0051ce02f071f381f19b7f5d2486437f8d Mon Sep 17 00:00:00 2001 From: Jim Nicholson Date: Thu, 8 Feb 2024 20:58:07 -0800 Subject: [PATCH] Refine the parsing to work with various situations --- vars/addVersionFromNexusRepo.groovy | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) 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 }