Skip to content

Build result condition

Damian Szczepanik edited this page Dec 8, 2019 · 12 revisions

This page presents example how to use BuildResult action:

Requirements

  • keep the 3 most recent build
  • keep at least one build with successful result

Configuration

pipeline {
    agent any
    options {
        buildDiscarder(

            BuildHistoryManager([
                [
                    continueAfterMatch: false,
                    matchAtMost: 3
                ],
                [
                    conditions: [ BuildResult(matchSuccess: true) ],
                    continueAfterMatch: false,
                    matchAtMost: 1
                ],
                [
                    actions: [ DeleteBuild() ]
                ]
            ])
            
        )
    }

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

Example

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

Before After Reason
[56]
success
[56]
success
Matched by first rule.
None action performed.
[54]
failure
[54]
failure
Matched by first rule.
None changes performed.
[52]
success
[52]
success
Matched by first rule.
None changes performed.
This is the last build matched by this rule because of matchAtMost: 3
[50]
failure
Matched by third rule as the second rule does not meet condition.
Build has been removed.
[41]
failure
Matched by third rule as the second rule does not meet condition.
Build has been removed.
[35]
success
[35]
success
Matched by second rule.
None changes performed.
This is the last build matched by this rule because of matchAtMost: 1
[32]
unstable
Matched by third rule as the second rule does not meet condition.
Build has been removed.
[30]
success
Matched by third rule.
Build has been removed.
Clone this wiki locally