Search code examples
groovyrepositoryjenkins-pipelineartifactoryartifactory-query-lang

Artifactory - delete artifacts older than 20 days


I am trying to integrate Jenkins with Artifactory. I have a groovy script for defining Jenkins pipeline Job. On the Artifactory, i have a repository for my project with many sub-folders. For every Jenkins new build, a new folder is created into Artifactory repo. The idea is that i don't know how to delete the folders and content artifacts which are older than 20 days. I used AQL to retrieve them, but i don't know how to delete what i retrieved. I can not use Artifactory Cleanup Plugin because i don't have access to install it on the platform.

Thank you


Solution

  • Before publishing the build-info, define 20 days build retention:

    // Delete build after 20 days
    buildInfo.retention maxDays: 20, deleteBuildArtifacts: true
    

    For more information: https://www.jfrog.com/confluence/display/RTF/Scripted+Pipeline+Syntax#ScriptedPipelineSyntax-TriggeringBuildRetention