From dab315646516c4570d165c27377301ddaf65a3ff Mon Sep 17 00:00:00 2001 From: sbussetti Date: Wed, 19 Sep 2018 11:49:07 -0400 Subject: [PATCH] Adds option to specify secret id for github Same as existing bitbucket checkout-over-ssh ssh-checkout for github must needs the option for a user to specify the id of the secret containing the ssh credentials to be used for checkout. Change-Id: I675c94c971e78d6ecd71d6f1446e0388430dab80 Signed-off-by: sbussetti --- jenkins_jobs/modules/project_multibranch.py | 19 ++++++++++++++++--- .../multibranch/fixtures/scm_github_full.xml | 4 +++- .../multibranch/fixtures/scm_github_full.yaml | 3 ++- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/jenkins_jobs/modules/project_multibranch.py b/jenkins_jobs/modules/project_multibranch.py index 0e8f05fdd..bfe460e9b 100644 --- a/jenkins_jobs/modules/project_multibranch.py +++ b/jenkins_jobs/modules/project_multibranch.py @@ -745,7 +745,11 @@ def github_scm(xml_parent, data): :arg str api-uri: The GitHub API uri for hosted / on-site GitHub. Must first be configured in Global Configuration. (default GitHub) - :arg bool ssh-checkout: Checkout over SSH. (default false) + :arg bool ssh-checkout: Checkout over SSH. + + * **credentials** ('str'): Credentials to use for + checkout of the repo over ssh. + :arg str credentials-id: Credentials used to scan branches and pull requests, check out sources and mark commit statuses. (optional) :arg str repo-owner: Specify the name of the GitHub Organization or @@ -852,12 +856,21 @@ def github_scm(xml_parent, data): helpers.convert_mapping_to_xml( bd, data, bd_mapping, fail_required=True) - if data.get('ssh-checkout', False): - XML.SubElement( + if data.get('ssh-checkout', None): + cossh = XML.SubElement( traits, ''.join([ github_path_dscore, '.SSHCheckoutTrait' ]) ) + if not isinstance(data.get('ssh-checkout'), bool): + cossh_credentials = [ + ('credentials', 'credentialsId', ''), + ] + helpers.convert_mapping_to_xml( + cossh, + data.get('ssh-checkout'), + cossh_credentials, + fail_required=True) if data.get('discover-tags', False): XML.SubElement( diff --git a/tests/multibranch/fixtures/scm_github_full.xml b/tests/multibranch/fixtures/scm_github_full.xml index ea8eee0dd..2802182eb 100644 --- a/tests/multibranch/fixtures/scm_github_full.xml +++ b/tests/multibranch/fixtures/scm_github_full.xml @@ -41,7 +41,9 @@ 3 - + + ssh_secret + 3 diff --git a/tests/multibranch/fixtures/scm_github_full.yaml b/tests/multibranch/fixtures/scm_github_full.yaml index d94da6fc4..272d5f12a 100644 --- a/tests/multibranch/fixtures/scm_github_full.yaml +++ b/tests/multibranch/fixtures/scm_github_full.yaml @@ -4,7 +4,8 @@ script-path: some.Jenkinsfile scm: - github: api-uri: http://example.org/github - ssh-checkout: true + ssh-checkout: + credentials: 'ssh_secret' repo: example-repo repo-owner: example-owner credentials-id: example-credential