使用 Artifactory 的 REST API 部署 jar 文件 [英] Using Artifactory's REST API to deploy jar file

查看:54
本文介绍了使用 Artifactory 的 REST API 部署 jar 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

鉴于此 api 文档,我使用 HTTPBuilder 和 Groovy 来构建我的查询?我已经尝试了很多东西,但我没有做对.

Given this api documentation, how would I use HTTPBuilder and Groovy to construct my query? I've tried multiple things but I'm not getting it right.

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 ->


    }

  }

这似乎让我有些了解,但它上传了一个空的 jar 文件.身体似乎完全被忽略了.删除它会产生相同的结果.我似乎找不到关于如何完成的很好的参考.

This seems to get me part way there, but it uploads an empty jar file. Seems like the body is completely ignored. Removing it produces the same result. I can't seem to find a good reference on how this is done.

推荐答案

上述文档中的 JSON 实际上是 Artifactory 对部署请求的响应.
对于部署,Artifactroy 只需要一个简单的 PUT 请求,例如:

The JSON in the mentioned documentation is actually Artifactory's response to the deployment request.
For deployment, Artifactroy requires only a simple PUT request, for example:

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'
) 

这篇关于使用 Artifactory 的 REST API 部署 jar 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆