From 9e51beb8044367fe46ca9636a715ebcb683703c5 Mon Sep 17 00:00:00 2001 From: Azat Khuzhin Date: Fri, 31 Mar 2017 20:44:35 +0300 Subject: [PATCH] scm: introduce parent-credentials for git submodules Jenkins Git plugin does not use your configured credentials for cloning submodules, but you can told it to use credentials from parent repository, by checking "Use credentials from default remote of parent repository", and this "parent-credentials" will set that option. So without this option jenkins git plugin will not be able to clone submodules, if they are not public available. The default value is "false", like in jenkins git plugin. See-also: https://issues.jenkins-ci.org/browse/JENKINS-20941 Change-Id: I1cfb3f45bb082f538eff1a9e64a03be27f759a5f Signed-off-by: Azat Khuzhin --- jenkins_jobs/modules/scm.py | 4 ++++ tests/macros/fixtures/scm/obj-in-scm-macro001.xml | 1 + tests/scm/fixtures/git-submodule01.xml | 1 + tests/scm/fixtures/git-submodule01.yaml | 1 + 4 files changed, 7 insertions(+) diff --git a/jenkins_jobs/modules/scm.py b/jenkins_jobs/modules/scm.py index d5dbe0c28..dbbfc8e90 100644 --- a/jenkins_jobs/modules/scm.py +++ b/jenkins_jobs/modules/scm.py @@ -181,6 +181,8 @@ def git(registry, xml_parent, data): * **tracking** (`bool`) - Retrieve the tip of the configured branch in .gitmodules (Uses '\-\-remote' option which requires git>=1.8.2) + * **parent-credentials** (`bool`) - Use credentials from default + remote of parent repository (default false). * **reference-repo** (`str`) - Path of the reference repo to use during clone (optional) * **timeout** (`int`) - Specify a timeout (in minutes) for @@ -396,6 +398,8 @@ def git(registry, xml_parent, data): data['submodule'].get('recursive', False)).lower() XML.SubElement(ext, 'trackingSubmodules').text = str( data['submodule'].get('tracking', False)).lower() + XML.SubElement(ext, 'parentCredentials').text = str( + data['submodule'].get('parent-credentials', False)).lower() XML.SubElement(ext, 'reference').text = str( data['submodule'].get('reference-repo', '')) XML.SubElement(ext, 'timeout').text = str( diff --git a/tests/macros/fixtures/scm/obj-in-scm-macro001.xml b/tests/macros/fixtures/scm/obj-in-scm-macro001.xml index 0dd63a6bb..e382ff61e 100644 --- a/tests/macros/fixtures/scm/obj-in-scm-macro001.xml +++ b/tests/macros/fixtures/scm/obj-in-scm-macro001.xml @@ -42,6 +42,7 @@ false true false + false 10 diff --git a/tests/scm/fixtures/git-submodule01.xml b/tests/scm/fixtures/git-submodule01.xml index 9aac9a467..3d36a7145 100644 --- a/tests/scm/fixtures/git-submodule01.xml +++ b/tests/scm/fixtures/git-submodule01.xml @@ -26,6 +26,7 @@ true true true + true /jenkins_home/.gitcache/submodules 15 diff --git a/tests/scm/fixtures/git-submodule01.yaml b/tests/scm/fixtures/git-submodule01.yaml index 014518d0b..dc2ab720b 100644 --- a/tests/scm/fixtures/git-submodule01.yaml +++ b/tests/scm/fixtures/git-submodule01.yaml @@ -5,5 +5,6 @@ scm: disable: true recursive: true tracking: true + parent-credentials: true reference-repo: /jenkins_home/.gitcache/submodules timeout: 15