Artifactory Artifact Cleanup Template (1.40 and higher)

JFrog Pipelines Documentation

Products
JFrog Pipelines
Content Type
User Guide
ft:sourceType
Paligo

The Artifactory Artifact Cleanup template is a Pipelines template that can be used to delete all Artifactory artifacts that have not been downloaded for the past n time units.

Prerequisites

  • Artifactory Artifact Cleanup template is available from Pipelines 1.31.2, but for following steps you need 1.40.

  • Artifactory version must be 7.49.0 or higher

Step 1: Create Integration

The Artifact Cleanup Template requires the following integration. For information about creating an integration, see Adding an Integration.

Integration Type

Integration Name

Comments

JFrog Platform Access Token Integration

  • jf_token

This integration is used to perform Artifactory operations and requires repository read/write permissions.

Step 2: Create Node Pools

For SaaS deployments, a node pool named default-dynamic-nodepool is available by default. For on-premise deployments, at least one node pool must be added and designated as the default node pool, and assigned at least one build node for pipelines to execute in the selected Project. For information about creating node pools, see Managing Pipelines Node Pools.

Step 3: Create Pipelines Source for Artifact Cleanup Template

  1. In your SCM repository, create a new directory named .jfrog-pipelines.

  2. In the directory, create two new files:

    • pipelines.yml

    • values.yml

  3. pipelines.yml: Add the following in the pipelines.yml file:

    valuesFilePath: ./values.yml
    include:
      template: jfrog/ArtifactCleanup/1.0.0

    Where:

    • valuesFilePath is the path where the values.yml file is stored.

  4. values.yml: Update the values.yml file to include the values required for the template. Here is a sample:

    shared:
      input:
        # [Required]
        jfrogTokenIntegration: jf_token
    
    artifactCleanup:
      metadata:
        # [Required]
        pipelineName: artifact_cleanup
    
        # [Optional] Default value: artifact_cleanup_property_bag
        propertyBagResourceName: artifact_cleanup_property_bag
    
        # [Optional] Default value: artifact_cleanup_cron_trigger
        cronTriggerResourceName: artifact_cleanup_cron_trigger
    
      controls:
        # [Optional] When defined with enabled: true then new Cron will be setup. Default expression: 0 0 5 ? * 1
        cron:
          enabled: false
          expression: "*/3 * * * *"
    
        # [Optional] List of comma separated Artifactory repo names for which jfrogTokenIntegration is provided.
        # Useful when using the pipeline with Cron.
        repos: "plugin-repo-1"
    
        # [Optional] Defaults to true, if not provided
        dryRun: "true"
    
        # [Optional] Defaults to 1000, if not provided
        paceTimeMS: 1000
    
        # [Optional] Defaults to 10, if not provided
        maxRepos: 10
    
        # [Optional] Defaults to 10, if not provided
        maxArtifacts: 100
    
    
    dockerCleanup:
      metadata:
        # [Required]
        pipelineName: docker_cleanup
    
        # [Optional] Default value: docker_cleanup_property_bag
        propertyBagResourceName: docker_cleanup_property_bag
    
        # [Optional] Default value: docker_cleanup_cron_trigger
        cronTriggerResourceName: docker_cleanup_cron_trigger
    
      controls:
        # [Optional] When defined with enabled: true then new Cron will be setup. Default expression: 0 0 5 ? * 1
        cron:
          enabled: false
          expression: "*/3 * * * *"
    
        # [Optional] List of comma separated Artifactory Docker repo names for which jfrogTokenIntegration is provided.
        # Useful when using the pipeline with Cron.
        repos: "km-docker-local"
    
        # [Optional] Defaults to true, if not provided
        dryRun: "false"
    
        # [Optional] Defaults to 1000, if not provided
        paceTimeMS: 1000
    
        # [Optional] Defaults to 10, if not provided
        maxRepos: 10
    
        # [Optional] Defaults to 10, if not provided
        maxArtifacts: 100

    The following parameters are mandatory:

    • jfrogTokenIntegration: Name of the JFrog Platform Access Token Integration that was created in Step 1.

    • artifactCleanup: Name of the artifactCleanup pipeline. This pipeline is used for cleaning up all artifacts except Docker.

    • pipelineName: Name of the DockerCleanup pipeline. This pipeline is used for cleaning up all Docker artifacts.

  5. In the JFrog Platform, go to Administration → Pipelines → Pipeline Sources and add the pipeline as a pipeline source.

    artifactCleanupSource.png

    After your Pipeline Source syncs successfully, you can view the newly added pipelines (artifact_cleanup and docker_artifact_cleanup) by navigating to My Pipelines on the left navbar and clicking Pipelines → My Pipelines.

    180146800.png
    180146801.png
  6. Go to Application → Pipelines → My Pipelines → All Pipelines, click either artifact_cleanup or docker_cleanup, click the custom trigger button and click the Environment Variables tab.

    180146807.png
  7. Click the Environment Variables tab and configure the available values as per your requirements. See the table below for information about each environment variable.

    180146747.png

    Parameter

    Description

    timeUnit

    The unit of the time interval. year, month, day, hour or minute are allowed values. Default is month.

    timeInterval

    The time interval to look back before deleting an artifact. Default 1.

    searchOn

    Parameter to choose the search condition. Defaults to search artifacts last downloaded before selected time.

    repos

    A comma-separated list of repositories to clean. This parameter is required.

    dryRun

    Dry run to test the settings. If this parameter is passed, artifacts will not actually be deleted. Set to true to perform a dry run. Default is false.

    paceTimeMS

    The number of milliseconds to delay between delete operations. Default is 1000ms.

    maxRepos

    The maximum number of repos to be cleaned from the list provided in the repos field. This is useful when you do not want to overload your Artifactory.

    For example, if the repositories a1, a2, a3, and a4 were listed as the repositories in the repos field and the number of maxRepos is 2, then only a1 and a2 are cleaned, and a3 and a4 are ignored.

    maxArtifacts

    The maximum number of artifacts to be cleaned across the listed repositories.

  8. After setting the environment variables, click Trigger Run.

  9. On successful completion of the run, you can view the logs to verify the status of the cleanup.

    180146746.png

    You can also download the Step Test Report & Artifacts to verify the results.

    180146806.png