Search code examples
artifactory

Artifactory REST API: How can I find builds for an artifact?


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.


Solution

  • 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"
      ...
    }