Simplify. We don't need to do everything

This commit is contained in:
Jim Nicholson 2024-02-08 19:15:47 -08:00
parent f13b691cdc
commit 29648d6ad4

View File

@ -11,30 +11,23 @@ Jenkins Plugin dependencies:
*/ */
// Define the enum Map call(Map config = [:], Map queryParams = [:]) {
enum BuildNumFlags { Map defaults = [
IS_COMMITS_SINCE_TAG,
IS_JOB_BUILD_NUMBER,
IS_FROM_QUERY
}
Map call(Map config = [:]) {
def defaults = [
nexusBase: 'https://repo.thejimnicholson.com', nexusBase: 'https://repo.thejimnicholson.com',
searchAPI: 'service/rest/v1/search', searchAPI: 'service/rest/v1/search',
buildFlag: BuildNumFlags.IS_FROM_QUERY, ]
queryParams: [
Map queryParamsDefaults: [
repository: 'tools', repository: 'tools',
sort: 'name', sort: 'name',
name: 'tests/test-something*' name: 'tests/test-something*'
] ]
]
Map runConfig = defaults + config Map runConfig = defaults + config
Map query = queryParamsDefaults + queryParams
nexusURL = runConfig.nexusBase + '/' + runConfig.searchAPI nexusURL = runConfig.nexusBase + '/' + runConfig.searchAPI
nexusSearch = buildUrlWithQueryParams(nexusURL, runConfig.queryParams) nexusSearch = buildUrlWithQueryParams(nexusURL, query)
response = httpRequest acceptType: 'APPLICATION_JSON', response = httpRequest acceptType: 'APPLICATION_JSON',
contentType: 'APPLICATION_JSON', contentType: 'APPLICATION_JSON',
@ -43,31 +36,13 @@ Map call(Map config = [:]) {
body = response.content body = response.content
assets = readJSON text: body assets = readJSON text: body
latest = assets.items.last() latest = assets.items.last()
version = latest.version version = latest.version
buildNumFromQuery = '1' buildNumFromQuery = '1'
if (version == null) { if ((latest.version ?: null) == null) {
matches = (latest.name =~ /.*-([0-9\.]+)-([0-9]+)\.)[0]/)[0] matches = (latest.name =~ /.*-([0-9\.]+)-([0-9]+)\.)[0]/)[0]
version = matches[1] version = matches[1]
buildNumFromQuery = matches[2] buildNumFromQuery = matches[2]
} }
switch (runConfig.buildFlag) {
case BuildNumFlags.IS_COMMITS_SINCE_TAG:
build = sh(
script: 'git rev-list $(git tag | tail -1).. --count',
returnStdout: true
).trim()
break
case BuildNumFlags.IS_JOB_BUILD_NUMBER:
build = env.BUILD_NUMBER
break
case BuildNumFlags.IS_FROM_QUERY:
build = buildNumFromQuery
break
default:
build = buildNumFromQuery
break
}
runConfig.nexusQuery = nexusSearch runConfig.nexusQuery = nexusSearch
runConfig.latestVersion = version runConfig.latestVersion = version
runConfig.latestBuild = build runConfig.latestBuild = build