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 <steve.bussetti@gmail.com>
This commit is contained in:
sbussetti 2018-09-19 11:49:07 -04:00 committed by STEPHEN S BUSSETTI
parent 20f561c55d
commit dab3156465
3 changed files with 21 additions and 5 deletions

View File

@ -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(

View File

@ -41,7 +41,9 @@
<org.jenkinsci.plugins.github__branch__source.BranchDiscoveryTrait>
<strategyId>3</strategyId>
</org.jenkinsci.plugins.github__branch__source.BranchDiscoveryTrait>
<org.jenkinsci.plugins.github__branch__source.SSHCheckoutTrait/>
<org.jenkinsci.plugins.github__branch__source.SSHCheckoutTrait>
<credentialsId>ssh_secret</credentialsId>
</org.jenkinsci.plugins.github__branch__source.SSHCheckoutTrait>
<org.jenkinsci.plugins.github__branch__source.TagDiscoveryTrait/>
<org.jenkinsci.plugins.github__branch__source.ForkPullRequestDiscoveryTrait>
<strategyId>3</strategyId>

View File

@ -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