Adding feature to specify the user id for jenkins user credentials
This feature allows one to specify the user id for the jenkins ssh-agent-credentials in the wrappers section of the yaml file. Also providing yaml and corresponding xml files for testing. Change-Id: I6c19945450c6ef55fead72c32594adb5a9b807c6
This commit is contained in:
parent
442d5c8a2c
commit
c50d14c6d4
@ -24,6 +24,7 @@ Wrappers can alter the way the build is run as well as the build output.
|
||||
|
||||
import xml.etree.ElementTree as XML
|
||||
import jenkins_jobs.modules.base
|
||||
from jenkins_jobs.errors import JenkinsJobsException
|
||||
from jenkins_jobs.modules.builders import create_builders
|
||||
|
||||
|
||||
@ -1014,6 +1015,32 @@ def exclusion(parser, xml_parent, data):
|
||||
XML.SubElement(dit, 'name').text = str(resource).upper()
|
||||
|
||||
|
||||
def ssh_agent_credentials(parser, xml_parent, data):
|
||||
"""yaml: ssh-agent-credentials
|
||||
Sets up the user for the ssh agent plugin for jenkins.
|
||||
|
||||
Requires the Jenkins `SSH-Agent Plugin.
|
||||
<https://wiki.jenkins-ci.org/display/JENKINS/SSH-Agent-Plugin>`_
|
||||
|
||||
:arg str user: The user id of the jenkins user credentials (required)
|
||||
|
||||
Example:
|
||||
|
||||
.. literalinclude::
|
||||
/../../tests/wrappers/fixtures/ssh-agent-credentials001.yaml
|
||||
|
||||
"""
|
||||
|
||||
entry_xml = XML.SubElement(
|
||||
xml_parent,
|
||||
'com.cloudbees.jenkins.plugins.sshagent.SSHAgentBuildWrapper')
|
||||
|
||||
try:
|
||||
XML.SubElement(entry_xml, 'user').text = data['user']
|
||||
except KeyError:
|
||||
raise JenkinsJobsException("Missing 'user' for ssh-agent-credentials")
|
||||
|
||||
|
||||
class Wrappers(jenkins_jobs.modules.base.Base):
|
||||
sequence = 80
|
||||
|
||||
|
@ -204,6 +204,7 @@ jenkins_jobs.wrappers =
|
||||
release=jenkins_jobs.modules.wrappers:release
|
||||
rvm-env=jenkins_jobs.modules.wrappers:rvm_env
|
||||
sauce-ondemand=jenkins_jobs.modules.wrappers:sauce_ondemand
|
||||
ssh-agent-credentials=jenkins_jobs.modules.wrappers:ssh_agent_credentials
|
||||
timeout=jenkins_jobs.modules.wrappers:timeout
|
||||
timestamps=jenkins_jobs.modules.wrappers:timestamps
|
||||
workspace-cleanup=jenkins_jobs.modules.wrappers:workspace_cleanup
|
||||
|
8
tests/wrappers/fixtures/ssh-agent-credentials001.xml
Normal file
8
tests/wrappers/fixtures/ssh-agent-credentials001.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>
|
3
tests/wrappers/fixtures/ssh-agent-credentials001.yaml
Normal file
3
tests/wrappers/fixtures/ssh-agent-credentials001.yaml
Normal file
@ -0,0 +1,3 @@
|
||||
wrappers:
|
||||
- ssh-agent-credentials:
|
||||
user: '49d20745-9889-4c02-b286-fc6fb89c36bd'
|
Loading…
Reference in New Issue
Block a user