Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Artifactory's REST API to deploy jar file

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


    }

  }

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.

like image 541
stuff22 Avatar asked Feb 09 '12 23:02

stuff22


People also ask

How do you push jars to Artifactory?

Go to the artifact browser, select the repository you want to upload to, and hit the Set Me Up button for instructions. You can upload a file using Artifactory UI. Go to the artifact browser, select the repository you want to upload to, and hit the Upload button for instructions.

How do you deploy a jar file in JFrog Artifactory using Jenkins?

Simply install the Jenkins Artifactory plugin, configure the Artifactory repository within the Jenkins tool and then include deployment to the Artifactory repository as one of the Jenkins build steps. The Jenkins Artifactory plugin is easily integrated into Jenkins build jobs.


1 Answers

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'
) 
like image 170
noamt Avatar answered Sep 23 '22 12:09

noamt