diff --git a/jenkins_jobs/modules/wrappers.py b/jenkins_jobs/modules/wrappers.py index 6c660f98c..c755e11a5 100644 --- a/jenkins_jobs/modules/wrappers.py +++ b/jenkins_jobs/modules/wrappers.py @@ -424,22 +424,21 @@ def locks(parser, xml_parent, data): :arg: list of locks to use - Example:: + Example: - wrappers: - - locks: - - FOO - - FOO2 + .. literalinclude:: /../../tests/wrappers/fixtures/locks002.yaml + :language: yaml """ - lw = XML.SubElement(xml_parent, - 'hudson.plugins.locksandlatches.LockWrapper') - locktop = XML.SubElement(lw, 'locks') locks = data - for lock in locks: - lockwrapper = XML.SubElement(locktop, - 'hudson.plugins.locksandlatches.' - 'LockWrapper_-LockWaitConfig') - XML.SubElement(lockwrapper, 'name').text = lock + if locks: + lw = XML.SubElement(xml_parent, + 'hudson.plugins.locksandlatches.LockWrapper') + locktop = XML.SubElement(lw, 'locks') + for lock in locks: + lockwrapper = XML.SubElement(locktop, + 'hudson.plugins.locksandlatches.' + 'LockWrapper_-LockWaitConfig') + XML.SubElement(lockwrapper, 'name').text = lock def copy_to_slave(parser, xml_parent, data): diff --git a/tests/wrappers/fixtures/locks001.xml b/tests/wrappers/fixtures/locks001.xml new file mode 100644 index 000000000..955631f2d --- /dev/null +++ b/tests/wrappers/fixtures/locks001.xml @@ -0,0 +1,4 @@ + + + + diff --git a/tests/wrappers/fixtures/locks001.yaml b/tests/wrappers/fixtures/locks001.yaml new file mode 100644 index 000000000..9585c38b2 --- /dev/null +++ b/tests/wrappers/fixtures/locks001.yaml @@ -0,0 +1,2 @@ +wrappers: + - locks: diff --git a/tests/wrappers/fixtures/locks002.xml b/tests/wrappers/fixtures/locks002.xml new file mode 100644 index 000000000..bb7ef6340 --- /dev/null +++ b/tests/wrappers/fixtures/locks002.xml @@ -0,0 +1,15 @@ + + + + + + + FOO + + + FOO2 + + + + + diff --git a/tests/wrappers/fixtures/locks002.yaml b/tests/wrappers/fixtures/locks002.yaml new file mode 100644 index 000000000..cdaa45c4d --- /dev/null +++ b/tests/wrappers/fixtures/locks002.yaml @@ -0,0 +1,4 @@ +wrappers: + - locks: + - FOO + - FOO2