groovy – 使用Artifactory的REST API来部署jar文件
发布时间:2020-12-14 16:36:27 所属栏目:大数据 来源:网络整理
导读:鉴于这个api documentation,我如何使用HTTPBuilder和Groovy构建我的查询?我尝试了很多东西,但我没有做对. def http = new HTTPBuilder()http.request('http://artifactory:8888/libs-snapshot-local/my/jar/1.0/test-jar-1.0.jar',PUT,JSON ) { req - body
鉴于这个api
documentation,我如何使用HTTPBuilder和Groovy构建我的查询?我尝试了很多东西,但我没有做对.
def http = new HTTPBuilder() http.request('http://artifactory:8888/libs-snapshot-local/my/jar/1.0/test-jar-1.0.jar',PUT,JSON ) { req -> body = [ uri: "http://artifactory:8888/libs-snapshot-local/my/jar/1.0/test-jar-1.0.jar",downloadUri: "http://artifactory:8888/libs-snapshot-local/my/jar/1.0/test-jar-1.0.jar",repo: "libs-snapshot-local",path: "c:pathtojarfiletest.jar",created: "2012-02-03T08:37:12.599-0800",createdBy: "someuser",size: "1024",mimeType: "application/java-archive" ] response.success = { resp,json -> } } 这似乎让我分道扬but,但它上传了一个空的jar文件.好像身体完全被忽略了.删除它会产生相同的结果.我似乎无法找到关于如何完成的良好参考. 解决方法
上述文档中的JSON实际上是Artifactory对部署请求的响应.
对于部署,Artifactroy只需要一个简单的PUT请求,例如: def restClient = new RESTClient('http://localhost:8080/artifactory/libs-release-local/') restClient.auth.basic 'username','password' restClient.encoder.'application/zip' = this.&encodeZipFile def encodeZipFile(Object data) throws UnsupportedEncodingException { def entity = new FileEntity((File) data,'application/zip'); entity.setContentType('application/zip'); return entity } def response = restClient.put(path: 'org/artifact/1.0/artifact-1.0.jar',body: new File('/path/to/local/artifact.jar'),requestContentType: 'application/zip' ) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |