Search code examples
gradleartifactorygradle-pluginretentionnetflix-nebula-plugins

How to trigger Artifactory build retention from gradle


Is it possible to set build retention on Artifactory using gradle using the netflix nebula plugins?

I've searched the Internet and all I've been able to find is how to set build retention using Jenkins pipeline: buildInfo.retention maxBuilds: 10.

I've also found how to set build name and build number on Gradle Artifactory Plugin page:

clientConfig.info.setBuildName('new-strange-name')
clientConfig.info.setBuildNumber('1111')

However, I haven't found any information on how to specify build retention from gradle. I could use something like this:

clientConfig.info.setRetention(maxBuilds: 10, maxDays: 7)

Is it possible? If not, how can I achieve the same goal? Should I update the buildinfo of my build using the Jenkins pipeline plugin after the build was created and set the build retention there?


Solution

  • Using the Gradle Artifactory Plugin, you can use the artifactory extension to configure BuildInfo properties. From this extension you can access the BuildInfoHandler properties, like buildRetentionDays or buildRetentionMinimumDate as follows:

    artifactory {
        // publish & contextUrl  configuration
        // (...)
    
        clientConfig.info.setBuildName('custom-build-name')
        clientConfig.info.buildRetention.count = 10
        // see other configurable properties here :
        // https://github.com/jfrog/build-info/blob/branch-gradle2/build-info-client/src/main/java/org/jfrog/build/client/ArtifactoryClientConfiguration.java
    }