如何编写流水线来丢弃旧版本? [英] How to write Pipeline to discard old builds?
问题描述
groovy 语法生成器不适用于示例步骤 properties: Set Job Properties
.我选择了 Discard old builds
,然后在 Max # of builds to keep
字段中输入 10
,然后 Generate Groovy
代码>,什么也没有出现.
The groovy syntax generator is NOT working for sample step properties: Set Job Properties
. I've selected Discard old builds
and then entered 10
in the Max # of builds to keep
field and then Generate Groovy
and nothing shows up.
Jenkins 版本:2.7
Jenkins version: 2.7
推荐答案
您可以使用 properties
方法,该方法嵌套在 BuildDiscarderProperty
中,最终拥有您想要的键放.我仍然没有可靠的方法来查找每个键的正确语法.经过多次猜测和检查:
You can use the properties
method which, nested within the BuildDiscarderProperty
eventually has the key you want to set. I still don't have a solid way to look up the correct syntax of each key. After much guessing and checking:
properties([[$class: 'BuildDiscarderProperty', strategy: [$class: 'LogRotator', artifactDaysToKeepStr: '', artifactNumToKeepStr: '', daysToKeepStr: '', numToKeepStr: '10']]]);
请注意,此代码段适用于脚本语法.
Note that this snippet is for scripted syntax.
这篇关于如何编写流水线来丢弃旧版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!