Into JenkinsFile https://github.com/jenkinsci/jenkins/blob/master/Jenkinsfile ufficiale è:
properties([[$class: 'jenkins.model.BuildDiscarderProperty', strategy:
[$class: 'LogRotator', numToKeepStr: '50', artifactNumToKeepStr: '20']
]])
Un esempio di uso personale con il plugin github e Jenkins gasdotto multiramo:
#!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
}
}
Nel mio Sonatype Nexus, ho creato un compito di ripulire il artefatti.
Non uso 'Artifactory', ma credo che sia possibile creare un task interno per cancellarlo.
È inoltre possibile rimuovere manualmente, nel caso di utilizzo Maven, è possibile seguire questo esempio:
How do you deal with maven-3 timestamped snapshots efficiently?
Spero che ho aiutato.
Posso chiedere cosa significa "3,4" in "doNotDiscardBuilds: [" 3 "," 4 "]' – uncletall
Significa che le build numerate # 3 e # 4 in Jenkins non verranno scartate. Questo non verrà aggiunto al maxBuilds, quindi se hai maxBuilds impostato su 10, manterrà le build # 3, # 4 e le ultime 8. – rasebo