From d30af4616a86d9fcdc9dbd52f999adc08e8a0637 Mon Sep 17 00:00:00 2001 From: tanhengyeow Date: Sat, 1 Sep 2018 21:20:16 +0800 Subject: [PATCH] credentials-binding: Add support for more options Change-Id: I0d193dbab5967b362d92bde58c5a43bacac86bd2 Signed-off-by: Tan Heng Yeow --- jenkins_jobs/modules/wrappers.py | 45 ++++++++++++++++++- .../wrappers/fixtures/credentials_binding.xml | 18 +++++++- .../fixtures/credentials_binding.yaml | 17 ++++++- 3 files changed, 77 insertions(+), 3 deletions(-) diff --git a/jenkins_jobs/modules/wrappers.py b/jenkins_jobs/modules/wrappers.py index 01949434f..610a98312 100644 --- a/jenkins_jobs/modules/wrappers.py +++ b/jenkins_jobs/modules/wrappers.py @@ -1856,6 +1856,24 @@ def credentials_binding(registry, xml_parent, data): * **secret-key** (`str`) Environment variable for the access secret key (Required for binding-type amazon-web-services) + * **key-file-variable** (`str`) Environment variable + to be set to the temporary path of the SSH key + file during the build. + * **username-variable** (`str`) Environment variable + to be set to the username during + the build. (optional) + * **passphrase-variable** (`str`) Environment + variable to be set to the password + during the build. (optional) + * **keystore-variable** (`str`) Environment + variable to be set to the temporary + keystore location during the build. + * **password-variable** (`str`) Environment + variable to be set to the password + during the build. + * **alias-variable** (`str`) Environment variable + to be set to the keystore alias name + of the certificate during the build. Example: @@ -1887,7 +1905,16 @@ def credentials_binding(registry, xml_parent, data): 'text': 'org.jenkinsci.plugins.credentialsbinding.impl.StringBinding', 'amazon-web-services': 'com.cloudbees.jenkins.plugins.awscredentials' - '.AmazonWebServicesCredentialsBinding' + '.AmazonWebServicesCredentialsBinding', + 'ssh-user-private-key': + 'org.jenkinsci.plugins.credentialsbinding' + '.impl.SSHUserPrivateKeyBinding', + 'docker-server-creds-binding': + 'org.jenkinsci.plugins.docker.commons' + '.credentials.DockerServerCredentialsBinding', + 'cert-multi-binding': + 'org.jenkinsci.plugins.credentialsbinding' + '.impl.CertificateMultiBinding' } for binding in data: for binding_type, params in binding.items(): @@ -1911,6 +1938,22 @@ def credentials_binding(registry, xml_parent, data): ] helpers.convert_mapping_to_xml( binding_xml, params, mapping, fail_required=True) + elif binding_type == 'ssh-user-private-key': + mapping = [ + ('key-file-variable', 'keyFileVariable', None), + ('username-variable', 'usernameVariable', ''), + ('passphrase-variable', 'passphraseVariable', ''), + ] + helpers.convert_mapping_to_xml( + binding_xml, params, mapping, fail_required=True) + elif binding_type == 'cert-multi-binding': + mapping = [ + ('keystore-variable', 'keystoreVariable', None), + ('password-variable', 'passwordVariable', None), + ('alias-variable', 'aliasVariable', None), + ] + helpers.convert_mapping_to_xml( + binding_xml, params, mapping, fail_required=True) else: mapping = [ ('variable', 'variable', None), diff --git a/tests/wrappers/fixtures/credentials_binding.xml b/tests/wrappers/fixtures/credentials_binding.xml index 2e4c3bf16..580047c1d 100644 --- a/tests/wrappers/fixtures/credentials_binding.xml +++ b/tests/wrappers/fixtures/credentials_binding.xml @@ -19,16 +19,32 @@ config_text b3e6f337-5d44-4f57-921c-1632d796caad + + config_docker_server + b3e6f337-5d44-4f57-921c-1632d796caae + myUsername myPassword - b3e6f337-5d44-4f57-921c-1632d796caae + b3e6f337-5d44-4f57-921c-1632d796caag AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY b3e6f337-5d44-4f57-921c-1632d796caaf + + KEY_FILE_VARIABLE + USER_NAME_VARIABLE + PASSPHRASE_VARIABLE + b3e6f337-5d44-4f57-921c-1632d796caah + + + KEYSTORE_VARIABLE + PASSWORD_VARIABLE + ALIAS_VARIABLE + b3e6f337-5d44-4f57-921c-1632d796caaj + diff --git a/tests/wrappers/fixtures/credentials_binding.yaml b/tests/wrappers/fixtures/credentials_binding.yaml index 651ef034a..45f9a17b4 100644 --- a/tests/wrappers/fixtures/credentials_binding.yaml +++ b/tests/wrappers/fixtures/credentials_binding.yaml @@ -12,9 +12,12 @@ wrappers: - text: credential-id: b3e6f337-5d44-4f57-921c-1632d796caad variable: config_text + - docker-server-creds-binding: + credential-id: b3e6f337-5d44-4f57-921c-1632d796caae + variable: config_docker_server - credentials-binding: - username-password-separated: - credential-id: b3e6f337-5d44-4f57-921c-1632d796caae + credential-id: b3e6f337-5d44-4f57-921c-1632d796caag username: myUsername password: myPassword - credentials-binding: @@ -22,3 +25,15 @@ wrappers: credential-id: b3e6f337-5d44-4f57-921c-1632d796caaf access-key: AWS_ACCESS_KEY_ID secret-key: AWS_SECRET_ACCESS_KEY + - credentials-binding: + - ssh-user-private-key: + credential-id: b3e6f337-5d44-4f57-921c-1632d796caah + key-file-variable: KEY_FILE_VARIABLE + username-variable: USER_NAME_VARIABLE + passphrase-variable: PASSPHRASE_VARIABLE + - credentials-binding: + - cert-multi-binding: + credential-id: b3e6f337-5d44-4f57-921c-1632d796caaj + keystore-variable: KEYSTORE_VARIABLE + password-variable: PASSWORD_VARIABLE + alias-variable: ALIAS_VARIABLE