Search code examples
groovyjenkins-pipelineartifactoryjenkins-groovy

How to get a list of subfolders and files in jfrog Artifactory


I am looking to fetch the subfolders and files inside jfrog artifactory repo and for that I am running the below script which I am running in Groovy

def test = sh(script: "curl -u uname:password -X POST -k https://artifactory.xxxx.com/artifactory/api/search/aql -d 'items.find({\"type\" : \"file\",\"\$or\":[{\"repo\" : {\"\$match\" : \"war*\"}, \"repo\" : {\"\$match\" : \"web*\"} }]}).include(\"name\",\"repo\",\"path\",\"size\").sort({\"\$desc\": [\"size\"]}).limit(10)'", returnStdout: true).trim()
echo "The list is ${test}"

But its not returning any value. Any solution would be helpful. Thanks


Solution

  • You can use api/storage get the children of a artifact path.

    For example, your Artifactory has repository: maven-prerelease-local for maven, you can open https://artifactory.xxxx.com/maven-prerelease-local in browser, it will list file and folders under it.

    By adding api/storage in URL, it will return a JSON response.

    def test = sh(script: """
      curl -u uname:password -X GET -k \
      "https://artifactory.xxxx.com/api/storage/maven-prerelease-local/com/xxx/xxx/"
    """, returnStdout: true).trim()
    
    echo "The list is ${test}"