Better regexp, remove workspace cleanup

This commit is contained in:
Jim Nicholson 2024-02-08 23:24:53 -08:00
parent 1d416ce821
commit 188e6f1ab3
3 changed files with 9 additions and 12 deletions

View File

@ -15,6 +15,9 @@
}, },
"Indentation": { "Indentation": {
"enabled": false "enabled": false
},
"NoDef": {
"enabled": false
} }
} }
} }

View File

@ -3,14 +3,10 @@
void call(Map config = [:], Closure body = { }) { void call(Map config = [:], Closure body = { }) {
Map defaults = [ Map defaults = [
stepName: 'Checkout', stepName: 'Checkout',
useJobSCM: true, useJobSCM: true
cleanWorkspace: true
] ]
runConfig = defaults + config runConfig = defaults + config
stage(runConfig.stepName) { stage(runConfig.stepName) {
if (runConfig.cleanWorkspace) {
cleanWs disableDeferredWipeout: true
}
printBanner(runConfig.stepName) printBanner(runConfig.stepName)
if (runConfig.useJobSCM) { if (runConfig.useJobSCM) {
checkout scm checkout scm

View File

@ -26,8 +26,7 @@ Map call(Map config = [:], Map queryParams = [:]) {
Map runConfig = defaults + config Map runConfig = defaults + config
Map query = queryParamsDefaults + queryParams Map query = queryParamsDefaults + queryParams
def version String version
def response
nexusURL = runConfig.nexusBase + '/' + runConfig.searchAPI nexusURL = runConfig.nexusBase + '/' + runConfig.searchAPI
nexusSearch = buildUrlWithQueryParams(nexusURL, query) nexusSearch = buildUrlWithQueryParams(nexusURL, query)
@ -37,18 +36,17 @@ Map call(Map config = [:], Map queryParams = [:]) {
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()) { if (assets.items && !assets.items.empty) {
latest = assets.items.last() latest = assets.items.last()
/* We have to use instanceof here. The value SHOULD be null, but it comes back /* We have to use instanceof here. The value SHOULD be null, but it comes back
as class rather than null. This is probably a bug in the Pipeline Utilities as class rather than null. This is probably a bug in the Pipeline Utilities
plugin. */ plugin. */
/* groovylint-disable-next-line Instanceof */ /* groovylint-disable-next-line Instanceof */
if (latest.version instanceof net.sf.json.JSONNull && latest.name) { if (latest.version instanceof net.sf.json.JSONNull && latest.name) {
echo "Search result version field was null, looking in name field for a version" echo 'Search result version field was null, looking in name field for a version'
def match = (latest.name =~ /(?<=-)([0-9\.]{1,3})(?:-|\.)[^-\.]+/) match = (latest.name =~ /(?<=-)(\d+\.\d+\.\d+)(?=[\.-].*)/)
if (!match) { if (!match) {
echo "Match: ${match}" echo "Match: ${match}"
error("Regular expression match failed for latest.name: ${latest.name}") error("Regular expression match failed for latest.name: ${latest.name}")