diff --git a/jenkins_jobs/modules/helpers.py b/jenkins_jobs/modules/helpers.py index 90daa9f5a..a694c86e2 100644 --- a/jenkins_jobs/modules/helpers.py +++ b/jenkins_jobs/modules/helpers.py @@ -156,3 +156,17 @@ def config_file_provider_settings(xml_parent, data): else: XML.SubElement(xml_parent, 'globalSettings', {'class': settings['default-global-settings']}) + + +def findbugs_settings(xml_parent, data): + # General Options + rank_priority = str(data.get('rank-priority', False)).lower() + XML.SubElement(xml_parent, 'isRankActivated').text = rank_priority + include_files = data.get('include-files', '') + XML.SubElement(xml_parent, 'includePattern').text = include_files + exclude_files = data.get('exclude-files', '') + XML.SubElement(xml_parent, 'excludePattern').text = exclude_files + use_previous_build = str(data.get('use-previous-build-as-reference', + False)).lower() + XML.SubElement(xml_parent, + 'usePreviousBuildAsReference').text = use_previous_build diff --git a/jenkins_jobs/modules/publishers.py b/jenkins_jobs/modules/publishers.py index 1591a8ff1..ecbd60f43 100644 --- a/jenkins_jobs/modules/publishers.py +++ b/jenkins_jobs/modules/publishers.py @@ -30,6 +30,7 @@ import xml.etree.ElementTree as XML 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 import logging import pkg_resources @@ -1074,6 +1075,77 @@ def violations(parser, xml_parent, data): XML.SubElement(config, 'encoding').text = 'default' +def findbugs(parser, xml_parent, data): + """yaml: findbugs + FindBugs reporting for builds + + Requires the Jenkins :jenkins-wiki:`FindBugs Plugin + `. + + :arg str pattern: specifies the generated raw FindBugs XML report files, + such as \*\*/findbugs.xml or \*\*/findbugsXml.xml. + (Optional) + :arg bool rank-priority: Use rank as priority (default: false) + :arg str include-files: Comma separated list of files to include. + (Optional) + :arg str exclude-files: Comma separated list of files to exclude. + (Optional) + :arg bool can-run-on-failed: Weather or not to run plug-in on failed builds + (default: false) + :arg bool should-detect-modules: Determines if Ant or Maven modules should + be detected for all files that contain + warnings. (default: false) + :arg int healthy: Sunny threshold (optional) + :arg int unhealthy: Stormy threshold (optional) + :arg str health-threshold: Threshold priority for health status + ('low', 'normal' or 'high', defaulted to 'low') + :arg bool dont-compute-new: If set to false, computes new warnings based on + the reference build (default true) + :arg bool use-delta-values: Use delta for new warnings. (Default: false) + :arg bool use-previous-build-as-reference: If set then the number of new + warnings will always be calculated based on the previous build. Otherwise + the reference build. (Default: false) + :arg bool use-stable-build-as-reference: The number of new warnings will be + calculated based on the last stable build, allowing reverts of unstable + builds where the number of warnings was decreased. (default false) + :arg dict thresholds: + :thresholds: + * **unstable** (`dict`) + :unstable: * **total-all** (`int`) + * **total-high** (`int`) + * **total-normal** (`int`) + * **total-low** (`int`) + * **new-all** (`int`) + * **new-high** (`int`) + * **new-normal** (`int`) + * **new-low** (`int`) + + * **failed** (`dict`) + :failed: * **total-all** (`int`) + * **total-high** (`int`) + * **total-normal** (`int`) + * **total-low** (`int`) + * **new-all** (`int`) + * **new-high** (`int`) + * **new-normal** (`int`) + * **new-low** (`int`) + + Minimal Example: + + .. literalinclude:: /../../tests/reporters/fixtures/findbugs-minimal.yaml + + Full Example: + + .. literalinclude:: /../../tests/publishers/fixtures/findbugs01.yaml + """ + findbugs = XML.SubElement(xml_parent, + 'hudson.plugins.findbugs.FindBugsPublisher') + findbugs.set('plugin', 'findbugs') + + findbugs_settings(findbugs, data) + build_trends_publisher('[FINDBUGS] ', findbugs, data) + + def checkstyle(parser, xml_parent, data): """yaml: checkstyle Publish trend reports with Checkstyle. diff --git a/jenkins_jobs/modules/reporters.py b/jenkins_jobs/modules/reporters.py index 75c6a0924..5cc813fe8 100644 --- a/jenkins_jobs/modules/reporters.py +++ b/jenkins_jobs/modules/reporters.py @@ -35,6 +35,7 @@ Example:: import xml.etree.ElementTree as XML import jenkins_jobs.modules.base from jenkins_jobs.modules.helpers import build_trends_publisher +from jenkins_jobs.modules.helpers import findbugs_settings from jenkins_jobs.errors import JenkinsJobsException @@ -132,18 +133,7 @@ def findbugs(parser, xml_parent, data): 'hudson.plugins.findbugs.FindBugsReporter') findbugs.set('plugin', 'findbugs') - # General Options - rank_priority = str(data.get('rank-priority', False)).lower() - XML.SubElement(findbugs, 'isRankActivated').text = rank_priority - include_files = data.get('include-files', '') - XML.SubElement(findbugs, 'includePattern').text = include_files - exclude_files = data.get('exclude-files', '') - XML.SubElement(findbugs, 'excludePattern').text = exclude_files - use_previous_build = str(data.get('use-previous-build-as-reference', - False)).lower() - XML.SubElement(findbugs, - 'usePreviousBuildAsReference').text = use_previous_build - + findbugs_settings(findbugs, data) build_trends_publisher('[FINDBUGS] ', findbugs, data) diff --git a/setup.cfg b/setup.cfg index f2c50a486..80036b31c 100644 --- a/setup.cfg +++ b/setup.cfg @@ -145,6 +145,7 @@ jenkins_jobs.publishers = email-ext=jenkins_jobs.modules.publishers:email_ext email=jenkins_jobs.modules.publishers:email emotional-jenkins=jenkins_jobs.modules.publishers:emotional_jenkins + findbugs=jenkins_jobs.modules.publishers:findbugs fingerprint=jenkins_jobs.modules.publishers:fingerprint fitnesse=jenkins_jobs.modules.publishers:fitnesse ftp=jenkins_jobs.modules.publishers:ftp diff --git a/tests/publishers/fixtures/findbugs01.xml b/tests/publishers/fixtures/findbugs01.xml new file mode 100644 index 000000000..d2f7bc68e --- /dev/null +++ b/tests/publishers/fixtures/findbugs01.xml @@ -0,0 +1,41 @@ + + + + + true + f,d,e,.* + a,c,d,.* + true + 80 + 10 + high + [FINDBUGS] + + true + true + true + + 90 + 80 + 50 + 20 + 95 + 85 + 55 + 25 + 80 + 70 + 40 + 10 + 85 + 75 + 45 + 15 + + true + false + false + **/findbugs.xml + + + diff --git a/tests/publishers/fixtures/findbugs01.yaml b/tests/publishers/fixtures/findbugs01.yaml new file mode 100644 index 000000000..f1a4b8914 --- /dev/null +++ b/tests/publishers/fixtures/findbugs01.yaml @@ -0,0 +1,35 @@ +publishers: + - findbugs: + pattern: '**/findbugs.xml' + rank-priority: true + include-files: 'f,d,e,.*' + exclude-files: 'a,c,d,.*' + can-run-on-failed: true + should-detect-modules: true + healthy: 80 + unhealthy: 10 + use-delta-values: true + health-threshold: 'high' + thresholds: + unstable: + total-all: 90 + total-high: 80 + total-normal: 50 + total-low: 20 + new-all: 95 + new-high: 85 + new-normal: 55 + new-low: 25 + failed: + total-all: 80 + total-high: 70 + total-normal: 40 + total-low: 10 + new-all: 85 + new-high: 75 + new-normal: 45 + new-low: 15 + dont-compute-new: false + use-delta-values: true + use-previous-build-as-reference: true + use-stable-build-as-reference: true