Reputation: 1106
How can I find the builds in Artifactory for a given artifact? This is in Artifactory Pro 3.9.x. The artifacts were created on jenkins and pushed to Artifactory through the Jenkins/Artifactory plugin.
The connection is exposed in the Artifactory Web UI (i.e. I can click the "Builds" tab for an artifact), but I can't seem to find the right API or AQL to do the same via the REST API.
Upvotes: 3
Views: 9335
Reputation: 333
I know this is an old question, but the accepted answer has some caveats.
For one, users without admin rights, cannot perform the necessary AQL query. Second, not all package types have the "build.Name" and "build.Number" properties (nuget and conan for example) However, for self-hosted versions of Artifactory, it is possible to create a simple plugin, where you can wrap any AQL query in.
For example:
import groovy.json.JsonBuilder
import org.artifactory.search.aql.AqlResult
executions {
buildInfoFromArtifact(groups: ['developers']){ params ->
def pkgname = params['pkgname'] ? params['pkgname'][0] as String : null
def queryResult = []
def aql = "builds.find({\"module.artifact.item.name\": \"" + fullName + "\"})"
asSystem{
searches.aql(aql){ AqlResult aql_result ->
aql_result.each{ item ->
log.info "found: $item"
queryResult.add(item)
result = 'Found'
}
}
}
def json = [result: result, aqlResult: queryResult]
message = new JsonBuilder(json).toPrettyString()
The "groups" in the execution definition allows you to control who can execute this execution.
The "asSystem" runs anything in the closure as "_system_"
More information can be found in the documentation https://www.jfrog.com/confluence/display/JFROG/User+Plugins
Upvotes: 0
Reputation: 20376
For Artifactory versions older than 4.2 which does not support the builds domain in AQL, you can find the artifact build by getting this information from the build.name
and build.number
properties. Any artifact deployed using the Artifactory build integration is annotated with those 2 properties.
For example:
$ curl -uadmin:password http://localhost:8081/artifactory/api/storage/libs-snapshot-local/org/jfrog/test/multi1/3.5-SNAPSHOT/multi1-3.5-20160112.080623-1.jar?properties=build.name,build.number
{
"properties" : {
"build.name" : [ "maven-example" ],
"build.number" : [ "8" ]
},
"uri" : "http://localhost:8081/artifactory/api/storage/libs-snapshot-local/org/jfrog/test/multi1/3.5-SNAPSHOT/multi1-3.5-20160112.080623-1.jar"
}
Once you have the build name and number, you can use the Build Info REST API to get the build information.
For example:
$ curl -u admin:password http://localhost:8081/artifactory/api/build/maven-example/8
{
"buildInfo" : {
"version" : "1.0.1",
"name" : "maven-example",
"number" : "8"
...
}
Upvotes: 4
Reputation: 22893
You can query for builds in AQL starting version 4.2.
With 4.2 you can write something like:
builds.find({"module.artifact.item.name": "artifactory.war"})
Upvotes: 5