Add Disable Failed Job Plugin support
Adds ability to disable failed jobs automatically. This requires the Jenkins Disable Failed Job Plugin. Change-Id: I0966a32338ffce55fef01681688b46aed55cfdd0 Signed-off-by: Fatih Degirmenci <fatih.degirmenci@ericsson.com>
This commit is contained in:
parent
0a9b5b7206
commit
40b01c6dae
@ -31,7 +31,9 @@ import jenkins_jobs.modules.base
|
||||
from jenkins_jobs.modules import hudson_model
|
||||
from jenkins_jobs.modules.helpers import build_trends_publisher
|
||||
from jenkins_jobs.modules.helpers import findbugs_settings
|
||||
from jenkins_jobs.errors import JenkinsJobsException, InvalidAttributeError
|
||||
from jenkins_jobs.errors import (InvalidAttributeError,
|
||||
JenkinsJobsException,
|
||||
MissingAttributeError)
|
||||
import logging
|
||||
import pkg_resources
|
||||
import sys
|
||||
@ -4506,6 +4508,56 @@ def naginator(parser, xml_parent, data):
|
||||
data.get('max-failed-builds', '0'))
|
||||
|
||||
|
||||
def disable_failed_job(parser, xml_parent, data):
|
||||
"""yaml: disable-failed-job
|
||||
Automatically disable failed jobs.
|
||||
|
||||
Requires the Jenkins :jenkins-wiki:`Disable Failed Job Plugin
|
||||
<Disable+Failed+Job+Plugin>`.
|
||||
|
||||
:arg str when-to-disable: The condition to disable the job. (required)
|
||||
Possible values are
|
||||
|
||||
* **Only Failure**
|
||||
* **Failure and Unstable**
|
||||
* **Unstable**
|
||||
|
||||
:arg int no-of-failures: Number of consecutive failures to disable the
|
||||
job. (optional)
|
||||
|
||||
Example:
|
||||
|
||||
.. literalinclude::
|
||||
/../../tests/publishers/fixtures/disable-failed-job001.yaml
|
||||
:language: yaml
|
||||
"""
|
||||
|
||||
xml_element = XML.SubElement(xml_parent, 'disableFailedJob.'
|
||||
'disableFailedJob.DisableFailedJob',
|
||||
{'plugin': 'disable-failed-job'})
|
||||
|
||||
valid_conditions = ['Only Failure',
|
||||
'Failure and Unstable',
|
||||
'Only Unstable']
|
||||
|
||||
try:
|
||||
disable_condition = str(data['when-to-disable'])
|
||||
except KeyError as e:
|
||||
raise MissingAttributeError(e.args[0])
|
||||
|
||||
if disable_condition not in valid_conditions:
|
||||
raise InvalidAttributeError('when-to-disable', disable_condition,
|
||||
valid_conditions)
|
||||
XML.SubElement(xml_element, 'whenDisable').text = disable_condition
|
||||
|
||||
if 'no-of-failures' in data:
|
||||
XML.SubElement(xml_element, 'failureTimes').text = str(data.get(
|
||||
'no-of-failures'))
|
||||
XML.SubElement(xml_element, 'optionalBrockChecked').text = 'true'
|
||||
else:
|
||||
XML.SubElement(xml_element, 'optionalBrockChecked').text = 'false'
|
||||
|
||||
|
||||
class Publishers(jenkins_jobs.modules.base.Base):
|
||||
sequence = 70
|
||||
|
||||
|
@ -149,6 +149,7 @@ jenkins_jobs.publishers =
|
||||
coverage=jenkins_jobs.modules.publishers:coverage
|
||||
cppcheck=jenkins_jobs.modules.publishers:cppcheck
|
||||
description-setter=jenkins_jobs.modules.publishers:description_setter
|
||||
disable-failed-job=jenkins_jobs.modules.publishers:disable_failed_job
|
||||
display-upstream-changes=jenkins_jobs.modules.publishers:display_upstream_changes
|
||||
downstream-ext=jenkins_jobs.modules.publishers:downstream_ext
|
||||
doxygen=jenkins_jobs.modules.publishers:doxygen
|
||||
|
10
tests/publishers/fixtures/disable-failed-job001.xml
Normal file
10
tests/publishers/fixtures/disable-failed-job001.xml
Normal file
@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<project>
|
||||
<publishers>
|
||||
<disableFailedJob.disableFailedJob.DisableFailedJob plugin="disable-failed-job">
|
||||
<whenDisable>Failure and Unstable</whenDisable>
|
||||
<failureTimes>3</failureTimes>
|
||||
<optionalBrockChecked>true</optionalBrockChecked>
|
||||
</disableFailedJob.disableFailedJob.DisableFailedJob>
|
||||
</publishers>
|
||||
</project>
|
4
tests/publishers/fixtures/disable-failed-job001.yaml
Normal file
4
tests/publishers/fixtures/disable-failed-job001.yaml
Normal file
@ -0,0 +1,4 @@
|
||||
publishers:
|
||||
- disable-failed-job:
|
||||
when-to-disable: 'Failure and Unstable'
|
||||
no-of-failures: 3
|
9
tests/publishers/fixtures/disable-failed-job002.xml
Normal file
9
tests/publishers/fixtures/disable-failed-job002.xml
Normal file
@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<project>
|
||||
<publishers>
|
||||
<disableFailedJob.disableFailedJob.DisableFailedJob plugin="disable-failed-job">
|
||||
<whenDisable>Only Failure</whenDisable>
|
||||
<optionalBrockChecked>false</optionalBrockChecked>
|
||||
</disableFailedJob.disableFailedJob.DisableFailedJob>
|
||||
</publishers>
|
||||
</project>
|
3
tests/publishers/fixtures/disable-failed-job002.yaml
Normal file
3
tests/publishers/fixtures/disable-failed-job002.yaml
Normal file
@ -0,0 +1,3 @@
|
||||
publishers:
|
||||
- disable-failed-job:
|
||||
when-to-disable: 'Only Failure'
|
Loading…
Reference in New Issue
Block a user