Merge "Fix SSH Agent plugin markup for empty list of users"

This commit is contained in:
Zuul 2022-04-12 16:13:27 +00:00 committed by Gerrit Code Review
commit 79a5cb8b11
8 changed files with 41 additions and 9 deletions

View File

@ -2035,10 +2035,6 @@ def ssh_agent_credentials(registry, xml_parent, data):
.. 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::
@ -2053,16 +2049,22 @@ def ssh_agent_credentials(registry, xml_parent, data):
logger = logging.getLogger(__name__)
plugin_info = registry.get_plugin_info("SSH Agent Plugin")
plugin_ver = pkg_resources.parse_version(
plugin_info.get("version", str(sys.maxsize))
)
entry_xml = XML.SubElement(
xml_parent, "com.cloudbees.jenkins.plugins.sshagent.SSHAgentBuildWrapper"
)
user_parent_entry_xml = entry_xml
xml_key = "user"
user_list = list()
if "users" in data:
user_list += data["users"]
if len(user_list) > 1:
entry_xml = XML.SubElement(entry_xml, "credentialIds")
if plugin_ver >= pkg_resources.parse_version("1.5.0"):
user_parent_entry_xml = XML.SubElement(entry_xml, "credentialIds")
xml_key = "string"
if "user" in data:
logger.warning(
@ -2081,7 +2083,7 @@ def ssh_agent_credentials(registry, xml_parent, data):
)
for user in user_list:
XML.SubElement(entry_xml, xml_key).text = user
XML.SubElement(user_parent_entry_xml, xml_key).text = user
mapping = [("ignore-missing-credentials", "ignoreMissing", False)]
helpers.convert_mapping_to_xml(entry_xml, data, mapping, fail_required=False)

View File

@ -6,8 +6,8 @@
<string>44747833-247a-407a-a98f-a5a2d785111c</string>
<string>f1c0f777-7ac6-43fd-b5c7-68b420aa1392</string>
<string>dd647a01-be21-402b-bfc5-a4e89be7d0c4</string>
<ignoreMissing>false</ignoreMissing>
</credentialIds>
<ignoreMissing>false</ignoreMissing>
</com.cloudbees.jenkins.plugins.sshagent.SSHAgentBuildWrapper>
</buildWrappers>
</project>

View File

@ -5,8 +5,8 @@
<credentialIds>
<string>44747833-247a-407a-a98f-a5a2d785111c</string>
<string>dd647a01-be21-402b-bfc5-a4e89be7d0c4</string>
<ignoreMissing>false</ignoreMissing>
</credentialIds>
<ignoreMissing>false</ignoreMissing>
</com.cloudbees.jenkins.plugins.sshagent.SSHAgentBuildWrapper>
</buildWrappers>
</project>

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<project>
<buildWrappers>
<com.cloudbees.jenkins.plugins.sshagent.SSHAgentBuildWrapper>
<credentialIds>
<string>49d20745-9889-4c02-b286-fc6fb89c36bd</string>
</credentialIds>
<ignoreMissing>false</ignoreMissing>
</com.cloudbees.jenkins.plugins.sshagent.SSHAgentBuildWrapper>
</buildWrappers>
</project>

View File

@ -0,0 +1,4 @@
wrappers:
- ssh-agent-credentials:
users:
- '49d20745-9889-4c02-b286-fc6fb89c36bd'

View File

@ -0,0 +1,3 @@
- longName: 'SSH Agent Plugin'
shortName: 'ssh-agent'
version: "1.4"

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<project>
<buildWrappers>
<com.cloudbees.jenkins.plugins.sshagent.SSHAgentBuildWrapper>
<credentialIds/>
<ignoreMissing>false</ignoreMissing>
</com.cloudbees.jenkins.plugins.sshagent.SSHAgentBuildWrapper>
</buildWrappers>
</project>

View File

@ -0,0 +1,3 @@
wrappers:
- ssh-agent-credentials:
users: []