Question

I am using artifactory version 3.0.4. I need to compute a list of versions for a specified artifact based on groupId:artifacId:*.

This seems possible using REST and the commercial version of artifactory:

https://www.jfrog.com/confluence/display/RTF/Artifactory+REST+API#ArtifactoryRESTAPI-ArtifactVersionSearch

I have the following in a groovy script:

@Grab(group='org.apache.httpcomponents', module='httpclient', version='4.3.2' )
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.HttpEntity;
import org.apache.http.util.EntityUtils
import org.apache.http.client.methods.HttpGet;
import org.apache.http.entity.InputStreamEntity;
import org.apache.http.impl.client.DefaultHttpClient;

def url = "http://artifactory:8089/artifactory/agg/libs-snapshot-local/com/mygroup/my-artifact/";
HttpGet request = new HttpGet(url);
DefaultHttpClient client = new DefaultHttpClient();
HttpResponse response = client.execute(request);

HttpEntity entity = response.getEntity();
String responseString = EntityUtils.toString(entity, "UTF-8");
println responseString

But the versions for my-artifact in the responseString is drowned in irrelevant information. Any suggestions to perform a more sensible request or do I need to parse that ugly string?

Was it helpful?

Solution

The specific call you asked for indeed requires artifactory pro. What this means:

before working on it you should compare the cost of implementing it vs. the cost of buying it (make sure you consider possible chance of wasting time on implementing other "pro" API features)

If your time still results to be cheaper and (if I understand the intent correctly) given artifact name and group id, you want to get list of versions.

what you can do is write a method that implements that "pro" api call. meaning:

  1. children_list = /api/storage/<repo>/<group id split by slashes>/<your artifact>/ | grep folder ="true"
  2. you can (should?) check whether the children actually have subchildren (built artifacts)
  3. go over the list items, and create the list of versions with subchildren

hope I'm not too confusing :-)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top