@@ -10,6 +10,26 @@ import org.artifactory.security.UserInfo
10
10
// 1. property file with scheduler config
11
11
// 2. fix numberArtifactsToKeep to keep provided number of artifacts, not deleting as much artifacts instead
12
12
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
+
13
33
def pluginGroup = ' deprecates'
14
34
15
35
executions {
@@ -35,8 +55,8 @@ private def artifactDeprecate(int months, String[] repos, log, dryRun = false, n
35
55
int cntNoDeletePermissions = 0
36
56
def artifactsCleanedUp = searches. artifactsCreatedOrModifiedInRange(null , monthsUntil, repos)
37
57
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 )
40
60
41
61
42
62
log. info " \n ===> sortedArtifactsCleanedUp: $sortedArtifactsCleanedUp \n\n ===> artifactsToDelete: $artifactsToDelete "
0 commit comments