【问题标题】:Using Artifactory's REST API to deploy jar file使用 Artifactory 的 REST API 部署 jar 文件
【发布时间】:2012-02-09 23:48:41
【问题描述】:

鉴于这个 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 ->


    }

  }

这似乎让我走到了那里,但它上传了一个空的 jar 文件。似乎身体被完全忽略了。删除它会产生相同的结果。我似乎无法找到有关如何完成此操作的良好参考。

【问题讨论】:

    标签: groovy gradle artifactory


    【解决方案1】:

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

    【讨论】:

    • 这成功了!谢谢!文档有点混乱。其中一些说“样本输出”,一些说“样本使用”。 Deploy api 有“示例用法”....我认为这将是如何调用 api。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多