diff --git a/vars/addVersionFromNexusRepo.groovy b/vars/addVersionFromNexusRepo.groovy index e397a97..e752003 100644 --- a/vars/addVersionFromNexusRepo.groovy +++ b/vars/addVersionFromNexusRepo.groovy @@ -1,6 +1,15 @@ #!/usr/bin/env groovy -// import java.net.URLEncoder +/* +Calculate the current version by querying a list of assets in a Nexus Repository. +Return '0.0.1' if there are no matching assets. + +Jenkins Plugin dependencies: + +- HTTP Request +- Plugin Utilty Steps + +*/ Map call(Map config = [:]) { Map defaults = [ @@ -15,10 +24,18 @@ Map call(Map config = [:]) { Map runConfig = defaults + config nexusURL = runConfig.nexusBase + '/' + runConfig.searchAPI - nexusSearch = buildUrlWithQueryParams(nexusURL, runConfig.queryParams) + response = httpRequest acceptType: 'APPLICATION_JSON', + contentType: 'APPLICATION_JSON', + url: nexusSearch, + wrapAsMultipart: false + body = response.content + assets = readJSON text: body + latest = assets.items.last() runConfig.nexusQuery = nexusSearch + runConfig.latestVersion = latest.name + return runConfig }