Adding the build-discarder property

This deprecates the logrotate generic element of the jobs, as it's not
supported anymore on jenkins>1.637, see:

    1cbbb23923

Change-Id: Ib086aef43e4833855b5827ad0ed3310e8db7d7b9
Signed-off-by: David Caro <dcaroest@redhat.com>
This commit is contained in:
David Caro 2016-01-28 21:55:39 +01:00
parent d36262728b
commit 1cf271a96e
6 changed files with 78 additions and 0 deletions

View File

@ -94,6 +94,8 @@ Example:
The Logrotate section allows you to automatically remove old build
history. It adds the ``logrotate`` attribute to the :ref:`Job`
definition. All logrotate attributes default to "-1" (keep forever).
**Deprecated on jenkins >=1.637**: use the ``build-discarder``
property instead
* **raw**:
If present, this section should contain a single **xml** entry. This XML
@ -101,6 +103,7 @@ Example:
"""
import logging
import xml.etree.ElementTree as XML
import jenkins_jobs.modules.base
@ -109,6 +112,7 @@ from jenkins_jobs.xml_config import remove_ignorable_whitespace
class General(jenkins_jobs.modules.base.Base):
sequence = 10
logrotate_warn_issued = False
def gen_xml(self, parser, xml, data):
jdk = data.get('jdk', None)
@ -165,6 +169,12 @@ class General(jenkins_jobs.modules.base.Base):
str(data['retry-count'])
if 'logrotate' in data:
if not self.logrotate_warn_issued:
logging.warn('logrotate is deprecated on jenkins>=1.637, use '
'the property build-discarder on newer jenkins '
'instead')
self.logrotate_warn_issued = True
lr_xml = XML.SubElement(xml, 'logRotator')
logrotate = data['logrotate']
lr_days = XML.SubElement(lr_xml, 'daysToKeep')

View File

@ -710,6 +710,40 @@ def rebuild(parser, xml_parent, data):
data.get('rebuild-disabled', False)).lower()
def build_discarder(parser, xml_parent, data):
"""yaml: build-discarder
:arg int days-to-keep: Number of days to keep builds for (default -1)
:arg int num-to-keep: Number of builds to keep (default -1)
:arg int artifact-days-to-keep: Number of days to keep builds with
artifacts (default -1)
:arg int artifact-num-to-keep: Number of builds with artifacts to keep
(default -1)
Example:
.. literalinclude::
/../../tests/properties/fixtures/build-discarder-001.yaml
:language: yaml
.. literalinclude::
/../../tests/properties/fixtures/build-discarder-002.yaml
:language: yaml
"""
base_sub = XML.SubElement(xml_parent,
'jenkins.model.BuildDiscarderProperty')
strategy = XML.SubElement(base_sub, 'strategy')
strategy.set('class', 'hudson.tasks.LogRotator')
days = XML.SubElement(strategy, 'daysToKeep')
days.text = str(data.get('days-to-keep', -1))
num = XML.SubElement(strategy, 'numToKeep')
num.text = str(data.get('num-to-keep', -1))
adays = XML.SubElement(strategy, 'artifactDaysToKeep')
adays.text = str(data.get('artifact-days-to-keep', -1))
anum = XML.SubElement(strategy, 'artifactNumToKeep')
anum.text = str(data.get('artifact-num-to-keep', -1))
class Properties(jenkins_jobs.modules.base.Base):
sequence = 20

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<project>
<properties>
<jenkins.model.BuildDiscarderProperty>
<strategy class="hudson.tasks.LogRotator">
<daysToKeep>42</daysToKeep>
<numToKeep>43</numToKeep>
<artifactDaysToKeep>44</artifactDaysToKeep>
<artifactNumToKeep>45</artifactNumToKeep>
</strategy>
</jenkins.model.BuildDiscarderProperty>
</properties>
</project>

View File

@ -0,0 +1,6 @@
properties:
- build-discarder:
days-to-keep: 42
num-to-keep: 43
artifact-days-to-keep: 44
artifact-num-to-keep: 45

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<project>
<properties>
<jenkins.model.BuildDiscarderProperty>
<strategy class="hudson.tasks.LogRotator">
<daysToKeep>-1</daysToKeep>
<numToKeep>-1</numToKeep>
<artifactDaysToKeep>-1</artifactDaysToKeep>
<artifactNumToKeep>-1</artifactNumToKeep>
</strategy>
</jenkins.model.BuildDiscarderProperty>
</properties>
</project>

View File

@ -0,0 +1,2 @@
properties:
- build-discarder