diff --git a/jenkins_jobs/modules/triggers.py b/jenkins_jobs/modules/triggers.py index 1e6e68059..e79fafa55 100644 --- a/jenkins_jobs/modules/triggers.py +++ b/jenkins_jobs/modules/triggers.py @@ -1257,35 +1257,44 @@ def monitor_folders(parser, xml_parent, data): Requires the Jenkins :jenkins-wiki:`Filesystem Trigger Plugin `. - :arg str path: Folder path to poll. (optional) + :arg str path: Folder path to poll. (default '') :arg list includes: Fileset includes setting that specifies the list of includes files. Basedir of the fileset is relative to the workspace - root. If no value is set, all files are used. (optional) + root. If no value is set, all files are used. (default '') :arg str excludes: The 'excludes' pattern. A file that matches this mask will not be polled even if it matches the mask specified in 'includes' - section. (optional) + section. (default '') :arg bool check-modification-date: Check last modification date. (default true) :arg bool check-content: Check content. (default true) - :arg bool check-fewer: Check fewer or more files (default true) + :arg bool check-fewer: Check fewer files (default true) :arg str cron: cron syntax of when to run (default '') - Example: + Full Example: - .. literalinclude:: /../../tests/triggers/fixtures/monitor_folders.yaml + .. literalinclude:: + /../../tests/triggers/fixtures/monitor-folders-full.yaml + :language: yaml + + Minimal Example: + + .. literalinclude:: + /../../tests/triggers/fixtures/monitor-folders-minimal.yaml + :language: yaml """ ft = XML.SubElement(xml_parent, ('org.jenkinsci.plugins.fstrigger.' 'triggers.FolderContentTrigger')) - path = data.get('path') - if path: - XML.SubElement(ft, 'path').text = path - includes = data.get('includes') - if includes: - XML.SubElement(ft, 'includes').text = ",".join(includes) - excludes = data.get('excludes') - if excludes: - XML.SubElement(ft, 'excludes').text = excludes - XML.SubElement(ft, 'spec').text = data.get('cron', '') + ft.set('plugin', 'fstrigger') + + mappings = [ + ('path', 'path', ''), + ('cron', 'spec', ''), + ] + convert_mapping_to_xml(ft, data, mappings, fail_required=True) + + includes = data.get('includes', '') + XML.SubElement(ft, 'includes').text = ",".join(includes) + XML.SubElement(ft, 'excludes').text = data.get('excludes', '') XML.SubElement(ft, 'excludeCheckLastModificationDate').text = str( not data.get('check-modification-date', True)).lower() XML.SubElement(ft, 'excludeCheckContent').text = str( diff --git a/tests/triggers/fixtures/monitor_folders.xml b/tests/triggers/fixtures/monitor-folders-full.xml similarity index 94% rename from tests/triggers/fixtures/monitor_folders.xml rename to tests/triggers/fixtures/monitor-folders-full.xml index f7da2b88f..399ceebfd 100644 --- a/tests/triggers/fixtures/monitor_folders.xml +++ b/tests/triggers/fixtures/monitor-folders-full.xml @@ -1,14 +1,14 @@ - + pathname + H/15 * * * * pattern1,pattern2 pattern1 - H/15 * * * * true true true - \ No newline at end of file + diff --git a/tests/triggers/fixtures/monitor_folders.yaml b/tests/triggers/fixtures/monitor-folders-full.yaml similarity index 71% rename from tests/triggers/fixtures/monitor_folders.yaml rename to tests/triggers/fixtures/monitor-folders-full.yaml index eda43d383..ab71ac512 100644 --- a/tests/triggers/fixtures/monitor_folders.yaml +++ b/tests/triggers/fixtures/monitor-folders-full.yaml @@ -2,10 +2,10 @@ triggers: - monitor-folders: path: 'pathname' includes: - - 'pattern1' - - 'pattern2' + - 'pattern1' + - 'pattern2' excludes: 'pattern1' check-modification-date: false check-content: false check-fewer: false - cron: 'H/15 * * * *' + cron: H/15 * * * * diff --git a/tests/triggers/fixtures/monitor-folders-minimal.xml b/tests/triggers/fixtures/monitor-folders-minimal.xml new file mode 100644 index 000000000..1564aef7b --- /dev/null +++ b/tests/triggers/fixtures/monitor-folders-minimal.xml @@ -0,0 +1,14 @@ + + + + + + + + + false + false + false + + + diff --git a/tests/triggers/fixtures/monitor-folders-minimal.yaml b/tests/triggers/fixtures/monitor-folders-minimal.yaml new file mode 100644 index 000000000..6ce84ad04 --- /dev/null +++ b/tests/triggers/fixtures/monitor-folders-minimal.yaml @@ -0,0 +1,2 @@ +triggers: + - monitor-folders