Groovy script which uses properties to mark artifacts (e.g tested, releasable, production) and then deletes old artifacts based on number in each state
Groovy Shell
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
gradle
src/main
.gitignore
CHANGES.md
MaxInState.csv
OSupload.csv
OrderStream.csv
OrderStreamStates.csv
README
SLMconfig.csv
build.gradle
config.csv
debugGroovy
gradle.properties
gradlew
gradlew.bat
logback.xml
settings.gradle
slmStates.csv
slmStates2.csv

README

There are now two groovy scripts in this project.  They can each be built and
run separately.  The chief reason they are in the same project is to share the
build / debug infrastructure.  ArtifactoryProcess is useful to maintain proudction
application artifacts in Artifactory, finally cleaning out older artifacts.
ArtifactoryUpload was broken out as its focus is on a single source directory
and uploads a set of artifacts into Artifactory following maven naming conventions. 

Invoke ArtifactoryProcess with:

groovy ArtifactoryProcess.groovy [--dry-run] [--full-log] --function <func> --value <val> --web-server http://YourWebServer --repository yourRepoName --domain <com/YourOrg> Version1 ...
 --domain domain         : Name of the domain to scan.
 --dry-run               : Don't change anything; just list what would be done
 --full-log              : Display miscellaneous steps for processing artifacts
 --function function     : function to perform on artifacts
 --maxDays maxDays       : max days to mark / delete artifact (ignores counts),
                           optional
 --maxInState maxInState : name of csv file with states and max counts, optional
 --minDays minDays       : min days before mark / delete artifacts (ignores
                           counts), optional
 --must-have mustHave    : property required before applying delete, mark,
                           download, size or clear, optional
 --offsetDays offsetDays : offset for min and max days to adjust for marking
                           delays
 --password password     : Password to use to access Artifactory server.
 --repository repoName   : Name of the repository to scan.
 --targetDir targetDir   : target directory for downloaded artifacts
 --userName userName     : userName to use to access Artifactory server
 --value value           : value to use with certain functions, often required
 --web-server webServer  : URL to use to access Artifactory server

  Example: groovy ArtifactoryProcess.groovy --domain domain --dry-run --full-log 
     --function function --maxDays maxDays --maxInState maxInState --minDays minDays
     --must-have mustHave --offsetDays offsetDays --password password 
     --repository repoName --targetDir targetDir --userName userName --value value
     --web-server webServer 1.0.1 1.0.2

  Columns in config csv files can be: 
     [ repoName, targetDir, maxInState, domain, value, userName, mustHave, 
       webServer, password, function, maxDays, minDays ]

The ArtifactoryProcess script can be used in a couple of main modes as well as
a sort of hyper mode.

The first mode is to mark sets of artifacts as being in a particular state, e.g.
groovy.bat ArtifactoryProcess.groovy --function mark --value production --web-server http://YourWebServer/ --repository yourRepoName --domain <com.YourOrg> --userName fill-in-userID --password fill-in-password 1.0.45-zdf
would mark all artifacts in yourRepoName with a version of 1.0.45-zdf as
being in production.

The other mode is to cleanup old artifacts.  This could be done in two stages
where previously marked artifacts are deleted and then additional artifacts
would be marked for deletion on the next run.

Whether the cleanup is done in two stages or one, the different states in which
an artifact can be is defined in a comma separated value (csv) file which has
the name of the state and the number of artifacts to retain in that state.  The
last entry in the MaxInState.csv file is an unnamed state and is the maximum
number of otherwise unmarked artifacts should be retained.

There is also a hyper-mode (function config) where each step of a clean up is
read from a comma separated value (csv) file.  In this case the first line will
name the parameters which are to be specified and the values for each step will
be in the following lines.  It is recommended that parameters like user ID and 
password be passed on the command line, not in the config file.

The download function can be used to download all the jar files which match the
version(s) provided.

The size function will provide the sum of the sizes of the artifacts for each of
the children of the specified node (it displays the first level children's size,
but recurses to the lowest level for the sum).

To run the script, it can be run from the git root as suggested above.  However,
this requires that groovy 2.3 or higher be installed (parameters to closure 
support was added then and is required for the closure implementation used).
This requires that your JVM be at least 1.7.  If you do not wish to install
groovy on your server, you can comment out the @Grapes sections at the top (oh 
for the conditional compilations of c days gone) and build the required jar file
with 'gradlew build'.  You can then run the utility with something like:
java -jar build/libs/artifactoryProcess-run.jar --dry-run --full-log --function mark --value tested --web-server http://YourWebServer/ --repository yourRepoName  --domain <com.YourOrg> --userName fill-in-userID --password fill-in-password 1.0.45-zdf

Invoke ArtifactoryUpload with:

cd d:\git\ArtifactoryProcess
groovy src/main/groovy/artifactoryProcess/ArtifactoryUpload.groovy 
 --function upload --sourceDir //ciJenkins/d$/ci/jobs/targetJob/builds/2014-11-17_12-17-07/archive/archived
 --value 1.0.6 --jarsToUpload OSupload.csv --domain com/yourDomain 
 --web-server http://artifactory/ --repository libs-release-test
 --userName someUser --password somePassword

groovy ArtifactoryProcess.groovy [--dry-run] [--full-log] --function <func> 
 --value <val> --web-server http://YourWebServer/
 --repository libs-release-local --domain <com/YourOrg> Version1 ...
 --domain domain             : Name of the domain to scan.
 --dry-run                   : Don't change anything; just list what would be
                               done
 --full-log                  : Display miscellaneous steps for processing artifacts
 --function function         : function to perform on artifacts
 --jarsToUpload jarsToUpload : name of csv file with jar files to upload
 --password password         : Password to use to access Artifactory server.
 --repository repoName       : Name of the repository to scan.
 --sourceDir sourceDir       : source directory for uploaded artifacts, optional
 --userName userName         : userName to use to access Artifactory server
 --value value               : value to use with certain functions, often
                               required
 --web-server webServer      : URL to use to access Artifactory server

  Example: groovy ArtifactoryProcess.groovy --domain domain --dry-run --full-log
  --function function --jarsToUpload jarsToUpload.csv --password password
  --repository repoName --sourceDir sourceDir --userName userName
  --value value --web-server webServer

  Supported functions include [config, upload]

  Columns in config csv files can be [dry-run, sourceDir, repoName, domain,
  value, userName, full-log, webServer, jarsToUpload, password, function]