Add support of multiple credentials for ssh-agent-credentials wrapper
ssh-agent-credentials wrapper supports multiple credentials like ssh-agent plugin v1.5 (https://wiki.jenkins-ci.org/display/JENKINS/SSH+Agent+Plugin) via 'users' parameter. 'user' parameter is retained for backward compatibility. Change-Id: I8a21dd0e7cba210818ffe30bbc5c7e73b56211cb Signed-off-by: Igor Gnatenko <ignatenko@mirantis.com>
This commit is contained in:
parent
db48ec11c6
commit
68c9cabeb6
@ -1154,23 +1154,66 @@ def ssh_agent_credentials(parser, xml_parent, data):
|
||||
|
||||
Requires the Jenkins :jenkins-wiki:`SSH-Agent Plugin <SSH+Agent+Plugin>`.
|
||||
|
||||
:arg str user: The user id of the jenkins user credentials (required)
|
||||
:arg list users: A list of Jenkins users credential IDs (required)
|
||||
:arg str user: The user id of the jenkins user credentials (deprecated)
|
||||
|
||||
Example:
|
||||
|
||||
.. literalinclude::
|
||||
/../../tests/wrappers/fixtures/ssh-agent-credentials002.yaml
|
||||
|
||||
|
||||
if both **users** and **user** parameters specified, **users** will be
|
||||
prefered, **user** will be ignored.
|
||||
|
||||
Example:
|
||||
|
||||
.. literalinclude::
|
||||
/../../tests/wrappers/fixtures/ssh-agent-credentials003.yaml
|
||||
|
||||
The **users** with one value in list equals to the **user**. In this
|
||||
case old style XML will be generated. Use this format if you use
|
||||
SSH-Agent plugin < 1.5.
|
||||
|
||||
Example:
|
||||
|
||||
.. literalinclude::
|
||||
/../../tests/wrappers/fixtures/ssh-agent-credentials004.yaml
|
||||
|
||||
equals to:
|
||||
|
||||
.. literalinclude::
|
||||
/../../tests/wrappers/fixtures/ssh-agent-credentials001.yaml
|
||||
|
||||
"""
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
entry_xml = XML.SubElement(
|
||||
xml_parent,
|
||||
'com.cloudbees.jenkins.plugins.sshagent.SSHAgentBuildWrapper')
|
||||
xml_key = 'user'
|
||||
|
||||
try:
|
||||
XML.SubElement(entry_xml, 'user').text = data['user']
|
||||
except KeyError:
|
||||
raise JenkinsJobsException("Missing 'user' for ssh-agent-credentials")
|
||||
user_list = list()
|
||||
if 'users' in data:
|
||||
user_list += data['users']
|
||||
if len(user_list) > 1:
|
||||
entry_xml = XML.SubElement(entry_xml, 'credentialIds')
|
||||
xml_key = 'string'
|
||||
if 'user' in data:
|
||||
logger.warn("Both 'users' and 'user' parameters specified for "
|
||||
"ssh-agent-credentials. 'users' is used, 'user' is "
|
||||
"ignored.")
|
||||
elif 'user' in data:
|
||||
logger.warn("The 'user' param has been deprecated, "
|
||||
"use the 'users' param instead.")
|
||||
user_list.append(data['user'])
|
||||
else:
|
||||
raise JenkinsJobsException("Missing 'user' or 'users' parameter "
|
||||
"for ssh-agent-credentials")
|
||||
|
||||
for user in user_list:
|
||||
XML.SubElement(entry_xml, xml_key).text = user
|
||||
|
||||
|
||||
def credentials_binding(parser, xml_parent, data):
|
||||
|
12
tests/wrappers/fixtures/ssh-agent-credentials002.xml
Normal file
12
tests/wrappers/fixtures/ssh-agent-credentials002.xml
Normal file
@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<project>
|
||||
<buildWrappers>
|
||||
<com.cloudbees.jenkins.plugins.sshagent.SSHAgentBuildWrapper>
|
||||
<credentialIds>
|
||||
<string>44747833-247a-407a-a98f-a5a2d785111c</string>
|
||||
<string>f1c0f777-7ac6-43fd-b5c7-68b420aa1392</string>
|
||||
<string>dd647a01-be21-402b-bfc5-a4e89be7d0c4</string>
|
||||
</credentialIds>
|
||||
</com.cloudbees.jenkins.plugins.sshagent.SSHAgentBuildWrapper>
|
||||
</buildWrappers>
|
||||
</project>
|
6
tests/wrappers/fixtures/ssh-agent-credentials002.yaml
Normal file
6
tests/wrappers/fixtures/ssh-agent-credentials002.yaml
Normal file
@ -0,0 +1,6 @@
|
||||
wrappers:
|
||||
- ssh-agent-credentials:
|
||||
users:
|
||||
- '44747833-247a-407a-a98f-a5a2d785111c'
|
||||
- 'f1c0f777-7ac6-43fd-b5c7-68b420aa1392'
|
||||
- 'dd647a01-be21-402b-bfc5-a4e89be7d0c4'
|
11
tests/wrappers/fixtures/ssh-agent-credentials003.xml
Normal file
11
tests/wrappers/fixtures/ssh-agent-credentials003.xml
Normal file
@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<project>
|
||||
<buildWrappers>
|
||||
<com.cloudbees.jenkins.plugins.sshagent.SSHAgentBuildWrapper>
|
||||
<credentialIds>
|
||||
<string>44747833-247a-407a-a98f-a5a2d785111c</string>
|
||||
<string>dd647a01-be21-402b-bfc5-a4e89be7d0c4</string>
|
||||
</credentialIds>
|
||||
</com.cloudbees.jenkins.plugins.sshagent.SSHAgentBuildWrapper>
|
||||
</buildWrappers>
|
||||
</project>
|
6
tests/wrappers/fixtures/ssh-agent-credentials003.yaml
Normal file
6
tests/wrappers/fixtures/ssh-agent-credentials003.yaml
Normal file
@ -0,0 +1,6 @@
|
||||
wrappers:
|
||||
- ssh-agent-credentials:
|
||||
user: '49d20745-9889-4c02-b286-fc6fb89c36bd'
|
||||
users:
|
||||
- '44747833-247a-407a-a98f-a5a2d785111c'
|
||||
- 'dd647a01-be21-402b-bfc5-a4e89be7d0c4'
|
8
tests/wrappers/fixtures/ssh-agent-credentials004.xml
Normal file
8
tests/wrappers/fixtures/ssh-agent-credentials004.xml
Normal file
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<project>
|
||||
<buildWrappers>
|
||||
<com.cloudbees.jenkins.plugins.sshagent.SSHAgentBuildWrapper>
|
||||
<user>49d20745-9889-4c02-b286-fc6fb89c36bd</user>
|
||||
</com.cloudbees.jenkins.plugins.sshagent.SSHAgentBuildWrapper>
|
||||
</buildWrappers>
|
||||
</project>
|
4
tests/wrappers/fixtures/ssh-agent-credentials004.yaml
Normal file
4
tests/wrappers/fixtures/ssh-agent-credentials004.yaml
Normal file
@ -0,0 +1,4 @@
|
||||
wrappers:
|
||||
- ssh-agent-credentials:
|
||||
users:
|
||||
- '49d20745-9889-4c02-b286-fc6fb89c36bd'
|
Loading…
Reference in New Issue
Block a user