From c8d07102946a0cc641dc8a129c29c0fc6f17ca19 Mon Sep 17 00:00:00 2001 From: Christian Fetzer Date: Wed, 27 Aug 2014 15:27:07 +0200 Subject: [PATCH] Add support for the Jenkins Clang Scan-Build publisher plugin. Change-Id: Ib892c790c370301e3e7ba04a83a9cfe38745c3ec --- jenkins_jobs/modules/publishers.py | 33 ++++++++++++++++++++ setup.cfg | 1 + tests/publishers/fixtures/scan-build001.xml | 9 ++++++ tests/publishers/fixtures/scan-build001.yaml | 4 +++ tests/publishers/fixtures/scan-build002.xml | 9 ++++++ tests/publishers/fixtures/scan-build002.yaml | 2 ++ 6 files changed, 58 insertions(+) create mode 100644 tests/publishers/fixtures/scan-build001.xml create mode 100644 tests/publishers/fixtures/scan-build001.yaml create mode 100644 tests/publishers/fixtures/scan-build002.xml create mode 100644 tests/publishers/fixtures/scan-build002.yaml diff --git a/jenkins_jobs/modules/publishers.py b/jenkins_jobs/modules/publishers.py index 6a8fbf96d..8c46633a1 100644 --- a/jenkins_jobs/modules/publishers.py +++ b/jenkins_jobs/modules/publishers.py @@ -3874,6 +3874,39 @@ def pmd(parser, xml_parent, data): build_trends_publisher('[PMD] ', xml_element, data) +def scan_build(parser, xml_parent, data): + """yaml: scan-build + Publishes results from the Clang scan-build static analyzer. + + The scan-build report has to be generated in the directory + ``${WORKSPACE}/clangScanBuildReports`` for the publisher to find it. + + Requires the Jenkins `Clang Scan-Build Plugin. + `_ + + :arg bool mark-unstable: Mark build as unstable if the number of bugs + exceeds a threshold (default: false) + :arg int threshold: Threshold for marking builds as unstable (default: 0) + + Example: + + .. literalinclude:: /../../tests/publishers/fixtures/scan-build001.yaml + + """ + threshold = str(data.get('threshold', 0)) + if not threshold.isdigit(): + raise JenkinsJobsException("Invalid value '%s' for threshold. " + "Numeric value expected." % threshold) + + p = XML.SubElement( + xml_parent, + 'jenkins.plugins.clangscanbuild.publisher.ClangScanBuildPublisher') + + XML.SubElement(p, 'markBuildUnstableWhenThresholdIsExceeded').text = \ + str(data.get('mark-unstable', False)).lower() + XML.SubElement(p, 'bugThreshold').text = threshold + + def create_publishers(parser, action): dummy_parent = XML.Element("dummy") parser.registry.dispatch('publisher', parser, dummy_parent, action) diff --git a/setup.cfg b/setup.cfg index c5fb1f4bf..40973b5c2 100644 --- a/setup.cfg +++ b/setup.cfg @@ -156,6 +156,7 @@ jenkins_jobs.publishers = robot=jenkins_jobs.modules.publishers:robot ruby-metrics=jenkins_jobs.modules.publishers:ruby_metrics s3=jenkins_jobs.modules.publishers:s3 + scan-build=jenkins_jobs.modules.publishers:scan_build scp=jenkins_jobs.modules.publishers:scp sitemonitor=jenkins_jobs.modules.publishers:sitemonitor sloccount=jenkins_jobs.modules.publishers:sloccount diff --git a/tests/publishers/fixtures/scan-build001.xml b/tests/publishers/fixtures/scan-build001.xml new file mode 100644 index 000000000..3c21d5ac7 --- /dev/null +++ b/tests/publishers/fixtures/scan-build001.xml @@ -0,0 +1,9 @@ + + + + + true + 0 + + + diff --git a/tests/publishers/fixtures/scan-build001.yaml b/tests/publishers/fixtures/scan-build001.yaml new file mode 100644 index 000000000..520c7de64 --- /dev/null +++ b/tests/publishers/fixtures/scan-build001.yaml @@ -0,0 +1,4 @@ +publishers: + - scan-build: + mark-unstable: true + threshold: 0 diff --git a/tests/publishers/fixtures/scan-build002.xml b/tests/publishers/fixtures/scan-build002.xml new file mode 100644 index 000000000..1664c8a3a --- /dev/null +++ b/tests/publishers/fixtures/scan-build002.xml @@ -0,0 +1,9 @@ + + + + + false + 0 + + + diff --git a/tests/publishers/fixtures/scan-build002.yaml b/tests/publishers/fixtures/scan-build002.yaml new file mode 100644 index 000000000..6b0d6c6a9 --- /dev/null +++ b/tests/publishers/fixtures/scan-build002.yaml @@ -0,0 +1,2 @@ +publishers: + - scan-build