jfrog / artifactory-scripts

Scripts for Artifactory (Usually, for REST API), community driven.
Apache License 2.0
150 stars 162 forks source link

Create ArtifactoryProcess.groovy #2

Closed brianpcarr closed 10 years ago

brianpcarr commented 10 years ago

Invoke with:

groovy ArtifactoryProcess.groovy [--dry-run] [--full-log] --function --value --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 : Log miscellaneous steps for processing artifacts --function function : function to perform on artifacts --maxInState maxInState : name of csv file with states and max counts, optional --must-have mustHave : property required before applying delete, mark, download or clear, optional --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 function above, often required --web-server webServer : URL to use to access Artifactory server

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

Supported functions include [clear, delete, config, download, mark, repoPrint]

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

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 --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.

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 --userName fill-in-userID --password fill-in-password 1.0.45-zdf

brianpcarr commented 10 years ago

Hi Baruch, I think I understand it now. I believe that I pushed 41 additional files, none of which are very interesting (many are what you need for the recommended gradlew) but, fortunately, they should all be in a subdirectory which won’t be too confusing. Thanks for your help with this. Brian

From: Baruch Sadogursky [mailto:notifications@github.com] Sent: Thursday, August 07, 2014 10:25 AM To: JFrogDev/artifactory-scripts Cc: Brian Carr Subject: Re: [artifactory-scripts] Create ArtifactoryProcess.groovy (#2)

Merged #2https://github.com/JFrogDev/artifactory-scripts/pull/2.

— Reply to this email directly or view it on GitHubhttps://github.com/JFrogDev/artifactory-scripts/pull/2#event-150284134.

jbaruch commented 10 years ago

Cool.

Thanks for the contribution!

On Thu, Aug 7, 2014 at 5:36 PM, Brian Carr notifications@github.com wrote:

Hi Baruch, I think I understand it now. I believe that I pushed 41 additional files, none of which are very interesting (many are what you need for the recommended gradlew) but, fortunately, they should all be in a subdirectory which won’t be too confusing. Thanks for your help with this. Brian

From: Baruch Sadogursky [mailto:notifications@github.com] Sent: Thursday, August 07, 2014 10:25 AM To: JFrogDev/artifactory-scripts Cc: Brian Carr Subject: Re: [artifactory-scripts] Create ArtifactoryProcess.groovy (#2)

Merged #2https://github.com/JFrogDev/artifactory-scripts/pull/2.

— Reply to this email directly or view it on GitHub< https://github.com/JFrogDev/artifactory-scripts/pull/2#event-150284134>.

— Reply to this email directly or view it on GitHub https://github.com/JFrogDev/artifactory-scripts/pull/2#issuecomment-51480206 .

Baruch.

@jbaruch https://twitter.com/jbaruch/