diff --git a/vars/addVersionFromNexusRepo.groovy b/vars/addVersionFromNexusRepo.groovy index 68627d4..ef8072a 100644 --- a/vars/addVersionFromNexusRepo.groovy +++ b/vars/addVersionFromNexusRepo.groovy @@ -1,19 +1,32 @@ #!/usr/bin/env groovy -import groovyx.net.http.URIBuilder +import java.net.URLEncoder Map call(Map config = [:]) { Map defaults = [ nexusBase: 'https://repo.thejimnicholson.com', searchAPI: 'service/rest/v1/search', - repositoryName: 'tools' + queryParams: [ + 'repository': 'tools', + 'sort': 'name', + 'name': 'test.something' + ] ] Map runConfig = defaults + config - nexusSearch = new URIBuilder(runConfig.nexusBase) - /* groovylint-disable-next-line UnnecessarySetter */ - nexusSearch.setPath(runConfig.searchAPI) - nexusSearch.addQueryParam('repository', runConfig.repositoryName) + nexusSearch = buildUrlWithQueryParams(runConfig.nexusBase, runConfig.queryParams) + runConfig.nexusQuery = nexusSearch return runConfig } + +def buildUrlWithQueryParams(baseUrl, queryParams) { + def url = baseUrl + if (!queryParams.empty) { + def queryParamsString = queryParams.collect { key, value -> + "${URLEncoder.encode(key, 'UTF-8')}=${URLEncoder.encode(value, 'UTF-8')}" + }.join('&') + url += '?' + queryParamsString + } + return url +}