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": {
"enabled": false
},
"NoDef": {
"enabled": false
}
}
}

View File

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

View File

@ -26,29 +26,27 @@ Map call(Map config = [:], Map queryParams = [:]) {
Map runConfig = defaults + config
Map query = queryParamsDefaults + queryParams
def version
def response
String version
nexusURL = runConfig.nexusBase + '/' + runConfig.searchAPI
nexusSearch = buildUrlWithQueryParams(nexusURL, query)
response = httpRequest acceptType: 'APPLICATION_JSON',
contentType: 'APPLICATION_JSON',
url: nexusSearch,
wrapAsMultipart: false
body = response.content
assets = readJSON text: body
if (assets.items && !assets.items.isEmpty()) {
if (assets.items && !assets.items.empty) {
latest = assets.items.last()
/* 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
plugin. */
/* groovylint-disable-next-line Instanceof */
if (latest.version instanceof net.sf.json.JSONNull && latest.name) {
echo "Search result version field was null, looking in name field for a version"
def match = (latest.name =~ /(?<=-)([0-9\.]{1,3})(?:-|\.)[^-\.]+/)
echo 'Search result version field was null, looking in name field for a version'
match = (latest.name =~ /(?<=-)(\d+\.\d+\.\d+)(?=[\.-].*)/)
if (!match) {
echo "Match: ${match}"
error("Regular expression match failed for latest.name: ${latest.name}")