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