使用Artifactory的REST API来部署jar文件

时间:2012-02-09 23:48:41

标签: groovy gradle artifactory

鉴于此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:\\pathtojarfile\\test.jar",
            created: "2012-02-03T08:37:12.599-0800",
            createdBy: "someuser",
            size: "1024",
            mimeType: "application/java-archive"

        ]

    response.success = { resp, json ->


    }

  }

这似乎让我分道扬but,但它上传了一个空的jar文件。好像身体完全被忽略了。删除它会产生相同的结果。我似乎无法找到关于如何做到的好参考。

1 个答案:

答案 0 :(得分:13)

上述文档中的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'
)