diff --git a/jenkins_jobs/modules/triggers.py b/jenkins_jobs/modules/triggers.py index ae8c5841e..0936f1da5 100644 --- a/jenkins_jobs/modules/triggers.py +++ b/jenkins_jobs/modules/triggers.py @@ -1607,9 +1607,16 @@ def monitor_files(registry, xml_parent, data): are being monitored. (default true) :arg str cron: cron syntax of when to run (default '') - Example: + Minimal Example: - .. literalinclude:: /../../tests/triggers/fixtures/monitor-files001.yaml + .. literalinclude:: + /../../tests/triggers/fixtures/monitor-files-minimal.yaml + :language: yaml + + Full Example: + + .. literalinclude:: + /../../tests/triggers/fixtures/monitor-files-full.yaml :language: yaml """ ft_prefix = 'org.jenkinsci.plugins.fstrigger.triggers.' @@ -1635,19 +1642,14 @@ def monitor_files(registry, xml_parent, data): files_tag = XML.SubElement(ft, 'fileInfo') for file_info in files: file_tag = XML.SubElement(files_tag, ft_prefix + 'FileNameTriggerInfo') - try: - XML.SubElement(file_tag, - 'filePathPattern').text = file_info['path'] - except KeyError: - raise MissingAttributeError('path') - - strategy = file_info.get('strategy', 'LATEST') - if strategy not in valid_strategies: - raise InvalidAttributeError('strategy', strategy, valid_strategies) - XML.SubElement(file_tag, 'strategy').text = strategy check_content = file_info.get('check-content', []) - XML.SubElement(file_tag, 'inspectingContentFile').text = str( - bool(check_content)).lower() + files_mapping = [ + ('path', 'filePathPattern', None), + ('strategy', 'strategy', 'LATEST', valid_strategies), + ('', 'inspectingContentFile', bool(check_content)), + ] + convert_mapping_to_xml( + file_tag, file_info, files_mapping, fail_required=True) base_content_tag = XML.SubElement(file_tag, 'contentFileTypes') for content in check_content: diff --git a/tests/triggers/fixtures/monitor-files001.xml b/tests/triggers/fixtures/monitor-files-full.xml similarity index 100% rename from tests/triggers/fixtures/monitor-files001.xml rename to tests/triggers/fixtures/monitor-files-full.xml diff --git a/tests/triggers/fixtures/monitor-files001.yaml b/tests/triggers/fixtures/monitor-files-full.yaml similarity index 100% rename from tests/triggers/fixtures/monitor-files001.yaml rename to tests/triggers/fixtures/monitor-files-full.yaml diff --git a/tests/triggers/fixtures/monitor-files-minimal.xml b/tests/triggers/fixtures/monitor-files-minimal.xml new file mode 100644 index 000000000..3f4f8f812 --- /dev/null +++ b/tests/triggers/fixtures/monitor-files-minimal.xml @@ -0,0 +1,16 @@ + + + + + + + + path1 + LATEST + false + + + + + + diff --git a/tests/triggers/fixtures/monitor-files-minimal.yaml b/tests/triggers/fixtures/monitor-files-minimal.yaml new file mode 100644 index 000000000..9788bace2 --- /dev/null +++ b/tests/triggers/fixtures/monitor-files-minimal.yaml @@ -0,0 +1,4 @@ +triggers: + - monitor-files: + files: + - path: 'path1'