How to write Pipeline to discard old builds?

前端 未结 9 793
暖寄归人
暖寄归人 2020-12-04 20:24

The groovy syntax generator is NOT working for sample step properties: Set Job Properties. I\'ve selected Discard old builds and then entered

相关标签:
9条回答
  • 2020-12-04 21:27

    As for declarative syntax, you can use the options block:

    pipeline {
      options {
        buildDiscarder(logRotator(numToKeepStr: '30', artifactNumToKeepStr: '30'))
      }
      ...
    }
    

    Parameters for logRotator (from the source code):

    • daysToKeepStr: history is only kept up to this days.
    • numToKeepStr: only this number of build logs are kept.
    • artifactDaysToKeepStr: artifacts are only kept up to this days.
    • artifactNumToKeepStr: only this number of builds have their artifacts kept.

    More information can be found in Cloudbees knowledge base and in the docs for options block.

    0 讨论(0)
  • 2020-12-04 21:29

    For Scripted Pipelines use:

    properties([
        buildDiscarder(logRotator(daysToKeepStr: '3', numToKeepStr: '3')),
    ])
    
    0 讨论(0)
  • 2020-12-04 21:30

    For declarative pipeline you can add this:

    options {
    
        buildDiscarder(
            logRotator(
                // number of build logs to keep
                numToKeepStr:'5',
                // history to keep in days
                daysToKeepStr: '15',
                // artifacts are kept for days
                artifactDaysToKeepStr: '15',
                // number of builds have their artifacts kept
                artifactNumToKeepStr: '5'
            )
        )
    }
    
    0 讨论(0)
提交回复
热议问题