wrappers: omit blank settings for ssh-user-private-key credential
For the ssh-user-private-key credential-wrapper, the "key-file-variable" setting is mandatory, but the "username-variable" and "passphrase-variable" settings are optional. Prior to this commit, if a user omitted "username-variable" or "passphrase-variable" settings, JJB would write empty <usernameVariable/> or <passphraseVariable/> entries. When both were empty, the credentials-binding plugin would crash with an error: IllegalArgumentException("Cannot use the same key in both secretValues and publicValues") To resolve this, do not write XML entries for these optional parameters when the user does not specify them. Add a minimal test case reproducer. Change-Id: I94a4437eee6a8fdaf655c1a3bf69d46844b225bc
This commit is contained in:
parent
ce865d4b9c
commit
787164e09a
@ -2207,11 +2207,11 @@ def credentials_binding(registry, xml_parent, data):
|
|||||||
binding_xml, params, mapping, fail_required=True
|
binding_xml, params, mapping, fail_required=True
|
||||||
)
|
)
|
||||||
elif binding_type == "ssh-user-private-key":
|
elif binding_type == "ssh-user-private-key":
|
||||||
mapping = [
|
mapping = [("key-file-variable", "keyFileVariable", None)]
|
||||||
("key-file-variable", "keyFileVariable", None),
|
if "username-variable" in params:
|
||||||
("username-variable", "usernameVariable", ""),
|
mapping.append(("username-variable", "usernameVariable", None))
|
||||||
("passphrase-variable", "passphraseVariable", ""),
|
if "passphrase-variable" in params:
|
||||||
]
|
mapping.append(("passphrase-variable", "passphraseVariable", None))
|
||||||
helpers.convert_mapping_to_xml(
|
helpers.convert_mapping_to_xml(
|
||||||
binding_xml, params, mapping, fail_required=True
|
binding_xml, params, mapping, fail_required=True
|
||||||
)
|
)
|
||||||
|
13
tests/wrappers/fixtures/credentials-binding-ssh-minimal.xml
Normal file
13
tests/wrappers/fixtures/credentials-binding-ssh-minimal.xml
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<project>
|
||||||
|
<buildWrappers>
|
||||||
|
<org.jenkinsci.plugins.credentialsbinding.impl.SecretBuildWrapper>
|
||||||
|
<bindings>
|
||||||
|
<org.jenkinsci.plugins.credentialsbinding.impl.SSHUserPrivateKeyBinding>
|
||||||
|
<keyFileVariable>KEY_FILE_VARIABLE</keyFileVariable>
|
||||||
|
<credentialsId>34eb8759-264e-4265-90f0-cb252ab1d2bf</credentialsId>
|
||||||
|
</org.jenkinsci.plugins.credentialsbinding.impl.SSHUserPrivateKeyBinding>
|
||||||
|
</bindings>
|
||||||
|
</org.jenkinsci.plugins.credentialsbinding.impl.SecretBuildWrapper>
|
||||||
|
</buildWrappers>
|
||||||
|
</project>
|
@ -0,0 +1,5 @@
|
|||||||
|
wrappers:
|
||||||
|
- credentials-binding:
|
||||||
|
- ssh-user-private-key:
|
||||||
|
credential-id: 34eb8759-264e-4265-90f0-cb252ab1d2bf
|
||||||
|
key-file-variable: KEY_FILE_VARIABLE
|
Loading…
Reference in New Issue
Block a user