From 54554db531b6c21a269c7b69b1ccdf669f7c5d7a Mon Sep 17 00:00:00 2001 From: Somay Jain Date: Wed, 29 Jul 2015 19:52:28 -0700 Subject: [PATCH] Adding support to monitor folders using FS trigger plugin Change-Id: I04d84b1ad7c32ed36d86a04a33c3d5afee73fd86 --- jenkins_jobs/modules/triggers.py | 43 ++++++++++++++++++++ setup.cfg | 1 + tests/triggers/fixtures/monitor_folders.xml | 14 +++++++ tests/triggers/fixtures/monitor_folders.yaml | 11 +++++ 4 files changed, 69 insertions(+) create mode 100644 tests/triggers/fixtures/monitor_folders.xml create mode 100644 tests/triggers/fixtures/monitor_folders.yaml diff --git a/jenkins_jobs/modules/triggers.py b/jenkins_jobs/modules/triggers.py index 46be24ad7..2c6ed7d56 100644 --- a/jenkins_jobs/modules/triggers.py +++ b/jenkins_jobs/modules/triggers.py @@ -940,6 +940,49 @@ def reverse(parser, xml_parent, data): str(hudson_model.THRESHOLDS[result]['complete']).lower() +def monitor_folders(parser, xml_parent, data): + """yaml: monitor-folders + Configure Jenkins to monitor folders. + Requires the Jenkins :jenkins-wiki:`Filesystem Trigger Plugin + `. + + :arg str path: Folder path to poll. (optional) + :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) + :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) + :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 str cron: cron syntax of when to run (default '') + + Example: + + .. literalinclude:: /../../tests/triggers/fixtures/monitor_folders.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', '') + XML.SubElement(ft, 'excludeCheckLastModificationDate').text = str( + not data.get('check-modification-date', True)).lower() + XML.SubElement(ft, 'excludeCheckContent').text = str( + not data.get('check-content', True)).lower() + XML.SubElement(ft, 'excludeCheckFewerOrMoreFiles').text = str( + not data.get('check-fewer', True)).lower() + + def ivy(parser, xml_parent, data): """yaml: ivy Poll with an Ivy script diff --git a/setup.cfg b/setup.cfg index fb0021c6e..de5d1076d 100644 --- a/setup.cfg +++ b/setup.cfg @@ -230,6 +230,7 @@ jenkins_jobs.triggers = gitlab-merge-request=jenkins_jobs.modules.triggers:gitlab_merge_request groovy-script=jenkins_jobs.modules.triggers:groovy_script ivy=jenkins_jobs.modules.triggers:ivy + monitor-folders=jenkins_jobs.modules.triggers:monitor_folders pollscm=jenkins_jobs.modules.triggers:pollscm raw=jenkins_jobs.modules.general:raw reverse=jenkins_jobs.modules.triggers:reverse diff --git a/tests/triggers/fixtures/monitor_folders.xml b/tests/triggers/fixtures/monitor_folders.xml new file mode 100644 index 000000000..f7da2b88f --- /dev/null +++ b/tests/triggers/fixtures/monitor_folders.xml @@ -0,0 +1,14 @@ + + + + + pathname + 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.yaml new file mode 100644 index 000000000..eda43d383 --- /dev/null +++ b/tests/triggers/fixtures/monitor_folders.yaml @@ -0,0 +1,11 @@ +triggers: + - monitor-folders: + path: 'pathname' + includes: + - 'pattern1' + - 'pattern2' + excludes: 'pattern1' + check-modification-date: false + check-content: false + check-fewer: false + cron: 'H/15 * * * *'