diff --git a/jenkins_jobs/modules/properties.py b/jenkins_jobs/modules/properties.py index 4c13b80c8..fb215de79 100644 --- a/jenkins_jobs/modules/properties.py +++ b/jenkins_jobs/modules/properties.py @@ -34,7 +34,7 @@ Example:: import xml.etree.ElementTree as XML import jenkins_jobs.modules.base -from jenkins_jobs.errors import JenkinsJobsException +from jenkins_jobs.errors import InvalidAttributeError, JenkinsJobsException import logging @@ -411,19 +411,21 @@ def build_blocker(parser, xml_parent, data): `. :arg bool use-build-blocker: Enable or disable build blocker - (optional) (default true) + (default true) :arg list blocking-jobs: One regular expression per line to select blocking jobs by their names. (required) + :arg str block-level: block build globally ('GLOBAL') or per node ('NODE') + (default 'GLOBAL') - Example:: + :arg str queue-scanning: scan build queue for all builds ('ALL') or only + buildable builds ('BUILDABLE') (default 'DISABLED')) - properties: - - build-blocker: - use-build-blocker: true - blocking-jobs: - - ".*-deploy" - - "^maintenance.*" + + Example: + + .. literalinclude:: \ + /../../tests/properties/fixtures/build-blocker01.yaml """ blocker = XML.SubElement(xml_parent, 'hudson.plugins.' @@ -439,6 +441,22 @@ def build_blocker(parser, xml_parent, data): jobs = jobs + value + '\n' XML.SubElement(blocker, 'blockingJobs').text = jobs + block_level_list = ('GLOBAL', 'NODE') + block_level = data.get('block-level', 'GLOBAL') + if block_level not in block_level_list: + raise InvalidAttributeError('block-level', + block_level, + block_level_list) + XML.SubElement(blocker, 'blockLevel').text = block_level + + queue_scanning_list = ('DISABLED', 'ALL', 'BUILDABLE') + queue_scanning = data.get('queue-scanning', 'DISABLED') + if queue_scanning not in queue_scanning_list: + raise InvalidAttributeError('queue-scanning', + queue_scanning, + queue_scanning_list) + XML.SubElement(blocker, 'scanQueueFor').text = queue_scanning + def copyartifact(parser, xml_parent, data): """yaml: copyartifact diff --git a/tests/properties/fixtures/build-blocker01.xml b/tests/properties/fixtures/build-blocker01.xml new file mode 100644 index 000000000..2af1fb0ce --- /dev/null +++ b/tests/properties/fixtures/build-blocker01.xml @@ -0,0 +1,13 @@ + + + + + true + .*-deploy +^maintenance.* + + GLOBAL + DISABLED + + + diff --git a/tests/properties/fixtures/build-blocker01.yaml b/tests/properties/fixtures/build-blocker01.yaml new file mode 100644 index 000000000..e7000b108 --- /dev/null +++ b/tests/properties/fixtures/build-blocker01.yaml @@ -0,0 +1,6 @@ +properties: + - build-blocker: + use-build-blocker: true + blocking-jobs: + - ".*-deploy" + - "^maintenance.*"