diff --git a/jenkins_jobs/modules/scm.py b/jenkins_jobs/modules/scm.py
index 4fa2d3131..d3827acd6 100644
--- a/jenkins_jobs/modules/scm.py
+++ b/jenkins_jobs/modules/scm.py
@@ -257,12 +257,6 @@ remoteName/\*')
XML.SubElement(bspec, 'name').text = branch
excluded_users = '\n'.join(data.get('excluded-users', []))
XML.SubElement(scm, 'excludedUsers').text = excluded_users
- if 'included-regions' in data:
- include_string = '\n'.join(data['included-regions'])
- XML.SubElement(scm, 'includedRegions').text = include_string
- if 'excluded-regions' in data:
- exclude_string = '\n'.join(data['excluded-regions'])
- XML.SubElement(scm, 'excludedRegions').text = exclude_string
if 'merge' in data:
merge = data['merge']
merge_strategies = ['default', 'resolve', 'recursive', 'octopus',
@@ -322,6 +316,16 @@ remoteName/\*')
exts_node = XML.SubElement(scm, 'extensions')
impl_prefix = 'hudson.plugins.git.extensions.impl.'
+ if 'included-regions' in data or 'excluded-regions' in data:
+ ext_name = XML.SubElement(exts_node,
+ 'hudson.plugins.git.extensions.impl.'
+ 'PathRestriction')
+ if 'included-regions' in data:
+ include_string = '\n'.join(data['included-regions'])
+ XML.SubElement(ext_name, 'includedRegions').text = include_string
+ if 'excluded-regions' in data:
+ exclude_string = '\n'.join(data['excluded-regions'])
+ XML.SubElement(ext_name, 'excludedRegions').text = exclude_string
if 'changelog-against' in data:
ext_name = impl_prefix + 'ChangelogToBranch'
ext = XML.SubElement(exts_node, ext_name)
diff --git a/tests/scm/fixtures/git-polling-path-restriction01.xml b/tests/scm/fixtures/git-polling-path-restriction01.xml
new file mode 100644
index 000000000..6ec4ed884
--- /dev/null
+++ b/tests/scm/fixtures/git-polling-path-restriction01.xml
@@ -0,0 +1,44 @@
+
+
+
+ 2
+
+
+ origin
+ +refs/heads/*:refs/remotes/origin/*
+ https://github.com/openstack-infra/jenkins-job-builder.git
+
+
+
+
+ **
+
+
+
+
+ false
+ false
+ false
+ false
+ true
+ false
+ false
+ Default
+
+
+
+
+
+ false
+
+ false
+ false
+
+
+ jenkins_jobs
+tests
+
+
+
+
+
diff --git a/tests/scm/fixtures/git-polling-path-restriction01.yaml b/tests/scm/fixtures/git-polling-path-restriction01.yaml
new file mode 100644
index 000000000..29390a66a
--- /dev/null
+++ b/tests/scm/fixtures/git-polling-path-restriction01.yaml
@@ -0,0 +1,6 @@
+scm:
+ - git:
+ url: https://github.com/openstack-infra/jenkins-job-builder.git
+ included-regions:
+ - jenkins_jobs
+ - tests
diff --git a/tests/scm/fixtures/git-polling-path-restriction02.xml b/tests/scm/fixtures/git-polling-path-restriction02.xml
new file mode 100644
index 000000000..e17a8fb4a
--- /dev/null
+++ b/tests/scm/fixtures/git-polling-path-restriction02.xml
@@ -0,0 +1,43 @@
+
+
+
+ 2
+
+
+ origin
+ +refs/heads/*:refs/remotes/origin/*
+ https://github.com/openstack-infra/jenkins-job-builder.git
+
+
+
+
+ **
+
+
+
+
+ false
+ false
+ false
+ false
+ true
+ false
+ false
+ Default
+
+
+
+
+
+ false
+
+ false
+ false
+
+
+ doc
+
+
+
+
+
diff --git a/tests/scm/fixtures/git-polling-path-restriction02.yaml b/tests/scm/fixtures/git-polling-path-restriction02.yaml
new file mode 100644
index 000000000..f9f33d41b
--- /dev/null
+++ b/tests/scm/fixtures/git-polling-path-restriction02.yaml
@@ -0,0 +1,5 @@
+scm:
+ - git:
+ url: https://github.com/openstack-infra/jenkins-job-builder.git
+ excluded-regions:
+ - doc