Into official JenkinsFile https://github.com/jenkinsci/jenkins/blob/master/Jenkinsfile has:
properties([[$class: 'jenkins.model.BuildDiscarderProperty', strategy:
[$class: 'LogRotator', numToKeepStr: '50', artifactNumToKeepStr: '20']
]])
A example of own use with github plugin and jenkins multibranch pipeline:
#!groovy
node {
try {
properties([
[
$class: 'jenkins.model.BuildDiscarderProperty',
strategy: [
$class: 'LogRotator',
numToKeepStr: '10'
]
],
[
$class: 'GithubProjectProperty',
displayName: '',
projectUrlStr: 'https://github.com/xxxxxxx/xxxxx-xxxx/'
]
])
env.JAVA_HOME = tool 'JDK8'
def mvnHome = tool 'Maven'
stage 'Clean Workspace'
deleteDir()
stage 'Git Checkout Source'
checkout scm
stage 'Build Maven Module'
sh "${mvnHome}/bin/mvn clean install -DskipTests=true -DskipITs=true -U"
stage 'Unit Test Maven Module'
sh "${mvnHome}/bin/mvn test -DskipTests=false -DskipITs=true"
stage 'Integration Test Maven Module'
sh "${mvnHome}/bin/mvn verify -DskipTests=true -DskipITs=false"
stage 'Nexus Deploy Artifact'
sh "${mvnHome}/bin/mvn deploy:deploy -Pnexus-deploy"
stage 'Trigger Job xxxxxx-xxxxxx /master'
build job: 'xxxxxx-xxxxxx/master', propagate: false, wait: false
stage 'Send Success Email'
mail from: '[email protected]',
to: '[email protected]',
subject: "[JENKINS] ${env.JOB_NAME} - Build # ${env.BUILD_NUMBER} - [SUCCESS]!",
body: "${env.JOB_NAME} - Build # ${env.BUILD_NUMBER} - SUCCESS!"
}
catch (Exception ex) {
mail from: '[email protected]',
to: '[email protected]',
subject: "FAILURE - [JENKINS] ${env.JOB_NAME} - Build # ${env.BUILD_NUMBER} - [FAILURE]!",
body: "${env.JOB_NAME} - Build # ${env.BUILD_NUMBER} - FAILURE (${ex.message})!"
throw ex
}
}
In my Sonatype Nexus, I created a task to clean up the artifacts.
I do not use 'Artifactory', but I believe you can create an internal task to clear it.
You can also manually remove, in the case of maven use, you can follow this example:
How do you deal with maven-3 timestamped snapshots efficiently?
I hope I helped you.