Skip to content

Commit 45b89c2

Browse files
added properties file for retention policy for docker
1 parent b6b6590 commit 45b89c2

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

cleanup/artifactDeprecate/artifactDeprecate.groovy

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,26 @@ import org.artifactory.security.UserInfo
1010
// 1. property file with scheduler config
1111
// 2. fix numberArtifactsToKeep to keep provided number of artifacts, not deleting as much artifacts instead
1212

13+
@Field final String PROPERTIES_FILE_PATH = "plugins/${this.class.name}.properties"
14+
def config = new ConfigSlurper().parse(new File(ctx.artifactoryHome.haAwareEtcDir, PROPERTIES_FILE_PATH).toURL())
15+
16+
config.policies.each{ policySettings ->
17+
def cron = policySettings[ 0 ] ? policySettings[ 0 ] as String : ["0 0 5 ? * 1"]
18+
def repos = policySettings[ 1 ] ? policySettings[ 1 ] as String[] : ["__none__"]
19+
def months = policySettings[ 2 ] ? policySettings[ 2 ] as int : 6
20+
def dryRun = policySettings[ 3 ] ? policySettings[ 3 ] as Boolean : false
21+
def numberArtifactsToKeep = policySettings[ 4 ] ? policySettings[ 4 ] as int : 3
22+
23+
log.info "Schedule job policy list: $config.policies"
24+
25+
jobs {
26+
"scheduledCleanup_$cron"(cron: cron) {
27+
log.info "Policy settings for scheduled run at($cron): repo list($repos), months($months), dryrun($dryRun), numberArtifactsToKeep($numberArtifactsToKeep)"
28+
artifactDeprecate( months, repos, log, dryRun, numberArtifactsToKeep )
29+
}
30+
}
31+
}
32+
1333
def pluginGroup = 'deprecates'
1434

1535
executions {
@@ -35,8 +55,8 @@ private def artifactDeprecate(int months, String[] repos, log, dryRun = false, n
3555
int cntNoDeletePermissions = 0
3656
def artifactsCleanedUp = searches.artifactsCreatedOrModifiedInRange(null, monthsUntil, repos)
3757
def sortedArtifactsCleanedUp = artifactsCleanedUp.sort { repositories.getItemInfo(it)?.lastUpdated }
38-
// Here we can use sortedArtifactsCleanedUp.length - numberArtifactsToKeep
39-
def artifactsToDelete = sortedArtifactsCleanedUp.take(numberArtifactsToKeep)
58+
int numberArtifactsToDelete = sortedArtifactsCleanedUp.size - numberArtifactsToKeep
59+
def artifactsToDelete = sortedArtifactsCleanedUp.take(numberArtifactsToDelete)
4060

4161

4262
log.info "\n ===> sortedArtifactsCleanedUp: $sortedArtifactsCleanedUp\n\n ===> artifactsToDelete: $artifactsToDelete"
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Support different policies for different repos. Parameters between '|' are optional
2-
// Policy syntax: [ <cron time>, [ <repo list> ], months |, <pause time>, <true|false dryrun> |, <true|false disablePropertiesSupport> |, <true|false keepRelease> |, releaseRegex | }
3-
// Example: [ "0 0 5 ? * 1", [ "libs-releases-local" ], 3, 500, true, true, true, ~/.*-\d+\.\d+\.\d+\.*/ ],
2+
// Policy syntax: [ <cron time>, [ <repo list> ], months |, <true|false dryrun> |, numberArtifactsToKeep | }
3+
// Example: [ "0 0 5 ? * 1", [ "libs-releases-local" ], 3, true, 3 ],
44
policies = [
5-
[ "0 0 5 ? * 1", [ "docker-local" ], 3, 500, true, true, true ],
5+
[ "0 0 5 ? * 1", [ "docker-local" ], 3, true, 3 ],
66
]

0 commit comments

Comments
 (0)