From e6398cf3733e9306999596b74d8810a9334dd8fc Mon Sep 17 00:00:00 2001 From: Vishal Bhoj Date: Fri, 5 Oct 2018 23:09:05 +0530 Subject: [PATCH] Set reference repo under clone options When we have cloneOptions in the generated with options like tags and reference filled outside of cloneOptions, The reference is not filled in the job configuration and this option will not work as expected. reference should alwasy be listed inside CloneOptions. Change-Id: I519d3c42f1b32ab27243b0f5c592e3d41e3230bb Signed-off-by: Vishal Bhoj --- jenkins_jobs/modules/scm.py | 3 ++ .../git-extensions-reference-repo.xml | 35 +++++++++++++++++++ .../git-extensions-reference-repo.yaml | 4 +++ 3 files changed, 42 insertions(+) create mode 100644 tests/scm/fixtures/git-extensions-reference-repo.xml create mode 100644 tests/scm/fixtures/git-extensions-reference-repo.yaml diff --git a/jenkins_jobs/modules/scm.py b/jenkins_jobs/modules/scm.py index 87429f8d9..6c68dc158 100644 --- a/jenkins_jobs/modules/scm.py +++ b/jenkins_jobs/modules/scm.py @@ -447,6 +447,7 @@ def git_extensions(xml_parent, data): "timeout", "do-not-fetch-tags", "honor-refspec", + "reference-repo", ) if any(key in data for key in clone_options): ext_name = impl_prefix + 'CloneOption' @@ -471,6 +472,8 @@ def git_extensions(xml_parent, data): if 'honor-refspec' in data: XML.SubElement(ext, 'honorRefspec').text = str( data.get('honor-refspec', False)).lower() + if 'reference-repo' in data: + XML.SubElement(ext, 'reference').text = str(data['reference-repo']) if not trait and 'sparse-checkout' in data: ext_name = impl_prefix + 'SparseCheckoutPaths' ext = XML.SubElement(xml_parent, ext_name) diff --git a/tests/scm/fixtures/git-extensions-reference-repo.xml b/tests/scm/fixtures/git-extensions-reference-repo.xml new file mode 100644 index 000000000..25e724dd3 --- /dev/null +++ b/tests/scm/fixtures/git-extensions-reference-repo.xml @@ -0,0 +1,35 @@ + + + + 2 + + + origin + +refs/heads/*:refs/remotes/origin/* + https://example.com/project.git + + + + + ** + + + false + false + false + false + Default + + /path/to/reference/repo.git + + + + + false + 1 + /path/to/reference/repo.git + + + + + diff --git a/tests/scm/fixtures/git-extensions-reference-repo.yaml b/tests/scm/fixtures/git-extensions-reference-repo.yaml new file mode 100644 index 000000000..24461d819 --- /dev/null +++ b/tests/scm/fixtures/git-extensions-reference-repo.yaml @@ -0,0 +1,4 @@ +scm: + - git: + url: https://example.com/project.git + reference-repo: /path/to/reference/repo.git