Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get properties of an Artifact in Artifactory

In Artifactory, I have an artifact "consumersvc" and there are multiple version: 1.0.0, 1.1.0, 1.2.0 etc

Now, For each of these artifact versions, there are some properties attached to the build artifact of that artifact-x.x.x for ex: svnURL, svnChangeSetNumber etc

Is there any way I can get this info using Rest API etc.

I tried the following but it lists all the artifacts which has this property=value but I'm looking the opposite of that.

http://myartifactorysrvr.my.company.com:8080/artifactory/api/search/prop?svnURL=*

Then, it outputs info in JSON output and shows all artifacts in Artifactory where this property is set to any value. What I am looking for is, how to get all properties (svnURL and svnChangeSetNumber) for any artifact in Artifactory?

like image 529
unknown Avatar asked Aug 28 '15 18:08

unknown


2 Answers

You can use the Artifactory query language (AQL) for such queries.

For example, the following simple query will return the properties of all artifacts in repository libs-releases-local which are annotated with the property svnURL:

items.find({"$and" : [{"repo" : "libs-releases-local"}, {"@svnURL" : "*"}]}).include("property.*")

You can run such a query using the Artifactory rest API, for example using curl:

curl -vv -uuser:pass -X POST -H "Content-Type: application/json" -d @aql.txt http://localhost:8081/artifactory/api/search/aql

where aql.txt is a file containing the query.

This is an example of a rather simple query. The link above shows many more capabilities of the Artifactory query language.

like image 164
Dror Bereznitsky Avatar answered Sep 21 '22 03:09

Dror Bereznitsky


For example: The artifact name is accesscontrol

and you want to find all builds OR the properties of accesscontrol-x.x.x artifact in Artifactory. You can do it using:

import groovy.json.*

def searchUrl = "http://myartifactorysrvr.my.company.com:8080/artifactory/api/search/artifact?name=accesscontrol&repos=libs-release-local"
def conn = searchUrl.toURL().openConnection()
conn.setRequestProperty("X-Result-Detail", "info, properties")
def searchResultTxt = conn.content.text
println "Found: ${searchResultTxt}"
def searchResults = new JsonSlurper().parseText(searchResultTxt)
def map = searchResults.results.findAll {  it.properties."vcs.revision" != null }.collect { it.properties['vcs.revision'][0] }.sort().reverse()
map

Then run this at $ prompt:

`which groovy` ./1.groovy |sed "s/\(\"properties\":\)/\n\1/g"|grep vcs.revision| sed "s/$/\n\n/"

You'll get output of all builds of the project which generated accesscontrol artifact and if any of those builds uploaded SVN changeset # as vcs.revision, you'll see that per line. This way, you'd know what was SVN URL and what Changeset was used to fetch the source code.

If you replace libs-release-local with other repositories, you can get more results OR use a virtual repository name (if you have created any in Artifactory) which will look into all repositories including remote repos.

like image 20
AKS Avatar answered Sep 19 '22 03:09

AKS