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.
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.
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.
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'
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With