diff --git a/jenkins_jobs/modules/project_multibranch.py b/jenkins_jobs/modules/project_multibranch.py index a5f7dd3b6..ac7c5ddf9 100644 --- a/jenkins_jobs/modules/project_multibranch.py +++ b/jenkins_jobs/modules/project_multibranch.py @@ -431,6 +431,8 @@ def bitbucket_scm(xml_parent, data): * **before** (`bool`) - Clean the workspace before checkout * **prune** (`bool`) - Prune remote branches (default false) * **shallow-clone** (`bool`) - Perform shallow clone (default false) + * **sparse-checkout** (dict) + * **paths** (list) - List of paths to sparse checkout. (optional) * **depth** (`int`) - Set shallow clone depth (default 1) * **do-not-fetch-tags** (`bool`) - Perform a clone without tags (default false) @@ -799,6 +801,8 @@ def git_scm(xml_parent, data): * **before** (`bool`) - Clean the workspace before checkout * **prune** (`bool`) - Prune remote branches (default false) * **shallow-clone** (`bool`) - Perform shallow clone (default false) + * **sparse-checkout** (dict) + * **paths** (list) - List of paths to sparse checkout. (optional) * **depth** (`int`) - Set shallow clone depth (default 1) * **do-not-fetch-tags** (`bool`) - Perform a clone without tags (default false) @@ -941,6 +945,8 @@ def github_scm(xml_parent, data): * **before** (`bool`) - Clean the workspace before checkout * **prune** (`bool`) - Prune remote branches (default false) * **shallow-clone** (`bool`) - Perform shallow clone (default false) + * **sparse-checkout** (dict) + * **paths** (list) - List of paths to sparse checkout. (optional) * **depth** (`int`) - Set shallow clone depth (default 1) * **do-not-fetch-tags** (`bool`) - Perform a clone without tags (default false) diff --git a/jenkins_jobs/modules/scm.py b/jenkins_jobs/modules/scm.py index 7d758c1e3..3a2571fc0 100644 --- a/jenkins_jobs/modules/scm.py +++ b/jenkins_jobs/modules/scm.py @@ -633,9 +633,14 @@ def git_extensions(xml_parent, data): if trait and skip_notifications: trait_name = "com.cloudbees.jenkins.plugins.bitbucket.notifications.SkipNotificationsTrait" XML.SubElement(xml_parent, trait_name) - if not trait and "sparse-checkout" in data: + if "sparse-checkout" in data: ext_name = impl_prefix + "SparseCheckoutPaths" - ext = XML.SubElement(xml_parent, ext_name) + if trait: + trait_name = "SparseCheckoutPathsTrait" + tr = XML.SubElement(xml_parent, trait_prefix + trait_name) + ext = XML.SubElement(tr, "extension", {"class": ext_name}) + else: + ext = XML.SubElement(xml_parent, ext_name) sparse_co = XML.SubElement(ext, "sparseCheckoutPaths") sparse_paths = data["sparse-checkout"].get("paths") if sparse_paths is not None: diff --git a/tests/multibranch/fixtures/scm_bitbucket_full.xml b/tests/multibranch/fixtures/scm_bitbucket_full.xml index 30c759e32..72c426b61 100644 --- a/tests/multibranch/fixtures/scm_bitbucket_full.xml +++ b/tests/multibranch/fixtures/scm_bitbucket_full.xml @@ -117,6 +117,21 @@ + + + + + path1 + + + path2 + + + path3 + + + + false diff --git a/tests/multibranch/fixtures/scm_bitbucket_full.yaml b/tests/multibranch/fixtures/scm_bitbucket_full.yaml index 8b1a02467..253d84d41 100644 --- a/tests/multibranch/fixtures/scm_bitbucket_full.yaml +++ b/tests/multibranch/fixtures/scm_bitbucket_full.yaml @@ -83,6 +83,11 @@ scm: user: CI System email: no-reply@ci.example.com prune: true + sparse-checkout: + paths: + - "path1" + - "path2" + - "path3" shallow-clone: true depth: 3 do-not-fetch-tags: true diff --git a/tests/multibranch/fixtures/scm_git_full.xml b/tests/multibranch/fixtures/scm_git_full.xml index c2c508cd7..98242da05 100644 --- a/tests/multibranch/fixtures/scm_git_full.xml +++ b/tests/multibranch/fixtures/scm_git_full.xml @@ -75,6 +75,21 @@ 100 + + + + + path1 + + + path2 + + + path3 + + + + false diff --git a/tests/multibranch/fixtures/scm_git_full.yaml b/tests/multibranch/fixtures/scm_git_full.yaml index a663ead86..4b3b164c3 100644 --- a/tests/multibranch/fixtures/scm_git_full.yaml +++ b/tests/multibranch/fixtures/scm_git_full.yaml @@ -71,6 +71,12 @@ scm: after: true before: true prune: true + local-branch: true + sparse-checkout: + paths: + - "path1" + - "path2" + - "path3" shallow-clone: true depth: 3 do-not-fetch-tags: true diff --git a/tests/multibranch/fixtures/scm_github_full.xml b/tests/multibranch/fixtures/scm_github_full.xml index 2c875df93..49451804b 100644 --- a/tests/multibranch/fixtures/scm_github_full.xml +++ b/tests/multibranch/fixtures/scm_github_full.xml @@ -99,6 +99,21 @@ + + + + + path1 + + + path2 + + + path3 + + + + false diff --git a/tests/multibranch/fixtures/scm_github_full.yaml b/tests/multibranch/fixtures/scm_github_full.yaml index 58fb335f6..cfd0feab6 100644 --- a/tests/multibranch/fixtures/scm_github_full.yaml +++ b/tests/multibranch/fixtures/scm_github_full.yaml @@ -79,6 +79,12 @@ scm: user: CI System email: no-reply@ci.example.com prune: true + local-branch: true + sparse-checkout: + paths: + - "path1" + - "path2" + - "path3" shallow-clone: true depth: 3 do-not-fetch-tags: true