我正在尝试使用groovy脚本和REST API搜索工件:
def query = ‘artifactory/api/search/artifact?name=at.mic.all.feature&repos=features-qa-test-snapshot’
def server = new RESTClient(‘http://mic-build2.mic.co.at:8081’)
server.parser.'application/vnd.org.jfrog.artifactory.search.ArtifactSearchResult+json' = server.parser.'application/json'
def resp = server.get(path: query)
这会导致异常:
groovyx.net.http.HttpResponseException: Bad Request
at groovyx.net.http.RESTClient.defaultFailureHandler(RESTClient.java:240)
at groovyx.net.http.HTTPBuilder.doRequest(HTTPBuilder.java:508)
at groovyx.net.http.RESTClient.get(RESTClient.java:118)
at groovyx.net.http.RESTClient$get.call(Unknown Source)
at Artifactory.getArtifacts(artifactory.groovy:157)
…
仅查看服务器和查询是否正确,我在浏览器中尝试了url =服务器+'/'+查询(= http://mic-build2.mic.co.at:8081/artifactory/api/search/artifact?name=at.mic.all.feature&repos=features-qa-test-snapshot),结果得到一个文件,其中包含我的搜索结果:
{“结果”:[{“ uri”:“ http://mic-build2.mic.co.at:8081/artifactory/api/storage/features-qa-test-snapshot/at/mic/all/feature/at.mic.all.feature/20130313002236/at.mic.all.feature-20130313002236-win32.win32.x86.zip”},…..}
因此,我的服务器和查询似乎还可以,但是无法在我的常规脚本中使用。
在此先感谢您的帮助,谢谢!
坦率
最佳答案
uri路径应以“ /”开头,HTTP客户端不会为您添加该路径。
def query = ‘/artifactory/api/search/artifact?name=at.mic.all.feature&repos=features-qa-test-snapshot’
这应该工作。