Skip to content

Delete artifacts action

Damian Szczepanik edited this page Nov 27, 2019 · 14 revisions

This page presents example how to use DeleteArtifacts action:

Requirements

  • at most two the most recent build should be saved
  • for at most three more artifacts should be deleted
  • all the rest must be deleted

Configuration

pipeline {

  agent any

  options {
    buildDiscarder(

        BuildHistoryManager([
            [
                continueAfterMatch: false,
                matchAtMost: 2
            ],
            [
                actions : [DeleteArtifacts()],
                continueAfterMatch: false,
                matchAtMost : 3
            ],
            [
                actions: [DeleteBuild()],
            ]
        ])
    )
  }

   stages {
      stage('Demo') {
         steps {
            echo "Hello!"
         }
      }
   }
}

Example

Following presents build history before and after running above configuration. Numbers refer to build number.

Before After Reason
[23]
with artifact
[23]
with artifact
Matched by first rule.
No action performed.
[24]
without artifact
[24]
without artifact
Matched by first rule, no changes performed.
This is the last build performed by first rule because of matchAtMost: 2
[25]
with artifact
[25]
without artifact
Matched by second rule, artifact has been deleted
[30]
without artifact
[30]
without artifact
Matched by second rule.
Artifact should be removed but it is not published.
[31]
without artifact
[31]
without artifact
Matched by second rule.
Artifact should be removed but it was not present.
This is the last build performed by first rule because of matchAtMost: 3
[32]
with artifact
Matched by second rule.
Build has been removed.
[35]
with artifact
Matched by second rule.
Build has been removed.
Clone this wiki locally