#!/usr/bin/env groovy // import java.net.URLEncoder Map call(Map config = [:]) { Map defaults = [ nexusBase: 'https://repo.thejimnicholson.com', searchAPI: 'service/rest/v1/search', queryParams: [ 'repository': 'tools', 'sort': 'name', 'name': 'tests/test-something*' ] ] Map runConfig = defaults + config nexusURL = runConfig.nexusBase + '/' + runConfig.searchAPI nexusSearch = buildUrlWithQueryParams(nexusURL, 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 }