Add publisher for Git Publisher support
This change adds functionality to configure the Git Publisher post-build action in Jenkins jobs. Git Publisher is used to push results of a build back to one or more Git repositories. Change-Id: I275762934aa12c5c859db7c96003af8c6824b744
This commit is contained in:
parent
a77fe9c75c
commit
fa5e91b1e2
|
@ -2675,6 +2675,134 @@ def plot(parser, xml_parent, data):
|
|||
XML.SubElement(plugin, 'style').text = style
|
||||
|
||||
|
||||
def git(parser, xml_parent, data):
|
||||
"""yaml: git
|
||||
This plugin will configure the Jenkins Git plugin to
|
||||
push merge results, tags, and/or branches to
|
||||
remote repositories after the job completes.
|
||||
|
||||
Requires the Jenkins `Git Plugin.
|
||||
<https://wiki.jenkins-ci.org/display/JENKINS/Git+Plugin>`_
|
||||
|
||||
:arg bool push-merge: push merges back to the origin specified in the
|
||||
pre-build merge options (Default: False)
|
||||
:arg bool push-only-if-success: Only push to remotes if the build succeeds
|
||||
- otherwise, nothing will be pushed.
|
||||
(Default: True)
|
||||
:arg list tags: tags to push at the completion of the build
|
||||
|
||||
:tag: * **remote** (`str`) remote repo name to push to
|
||||
(Default: 'origin')
|
||||
* **name** (`str`) name of tag to push
|
||||
* **message** (`str`) message content of the tag
|
||||
* **create-tag** (`bool`) whether or not to create the tag
|
||||
after the build, if this is False then the tag needs to
|
||||
exist locally (Default: False)
|
||||
* **update-tag** (`bool`) whether to overwrite a remote tag
|
||||
or not (Default: False)
|
||||
|
||||
:arg list branches: branches to push at the completion of the build
|
||||
|
||||
:branch: * **remote** (`str`) remote repo name to push to
|
||||
(Default: 'origin')
|
||||
* **name** (`str`) name of remote branch to push to
|
||||
|
||||
:arg list notes: notes to push at the completion of the build
|
||||
|
||||
:note: * **remote** (`str`) remote repo name to push to
|
||||
(Default: 'origin')
|
||||
* **message** (`str`) content of the note
|
||||
* **namespace** (`str`) namespace of the note
|
||||
(Default: master)
|
||||
* **replace-note** (`bool`) whether to overwrite a note or not
|
||||
(Default: False)
|
||||
|
||||
|
||||
Example::
|
||||
|
||||
publishers:
|
||||
- git:
|
||||
push-merge: true
|
||||
push-only-if-success: false
|
||||
tags:
|
||||
- tag:
|
||||
remote: tagremotename
|
||||
name: tagname
|
||||
message: "some tag message"
|
||||
create-tag: true
|
||||
update-tag: true
|
||||
branches:
|
||||
- branch:
|
||||
remote: branchremotename
|
||||
name: "some/branch"
|
||||
notes:
|
||||
- note:
|
||||
remote: remotename
|
||||
message: "some note to push"
|
||||
namespace: commits
|
||||
replace-note: true
|
||||
|
||||
"""
|
||||
mappings = [('push-merge', 'pushMerge', False),
|
||||
('push-only-if-success', 'pushOnlyIfSuccess', True)]
|
||||
|
||||
tag_mappings = [('remote', 'targetRepoName', 'origin'),
|
||||
('name', 'tagName', None),
|
||||
('message', 'tagMessage', ''),
|
||||
('create-tag', 'createTag', False),
|
||||
('update-tag', 'updateTag', False)]
|
||||
|
||||
branch_mappings = [('remote', 'targetRepoName', 'origin'),
|
||||
('name', 'branchName', None)]
|
||||
|
||||
note_mappings = [('remote', 'targetRepoName', 'origin'),
|
||||
('message', 'noteMsg', None),
|
||||
('namespace', 'noteNamespace', 'master'),
|
||||
('replace-note', 'noteReplace', False)]
|
||||
|
||||
def handle_entity_children(entity, entity_xml, child_mapping):
|
||||
for prop in child_mapping:
|
||||
opt, xmlopt, default_val = prop[:3]
|
||||
val = entity.get(opt, default_val)
|
||||
if val is None:
|
||||
raise Exception('Required option missing: %s' % opt)
|
||||
if type(val) == bool:
|
||||
val = str(val).lower()
|
||||
XML.SubElement(entity_xml, xmlopt).text = val
|
||||
|
||||
top = XML.SubElement(xml_parent, 'hudson.plugins.git.GitPublisher')
|
||||
XML.SubElement(top, 'configVersion').text = '2'
|
||||
handle_entity_children(data, top, mappings)
|
||||
|
||||
tags = data.get('tags', [])
|
||||
if tags:
|
||||
xml_tags = XML.SubElement(top, 'tagsToPush')
|
||||
for tag in tags:
|
||||
xml_tag = XML.SubElement(
|
||||
xml_tags,
|
||||
'hudson.plugins.git.GitPublisher_-TagToPush')
|
||||
handle_entity_children(tag['tag'], xml_tag, tag_mappings)
|
||||
|
||||
branches = data.get('branches', [])
|
||||
if branches:
|
||||
xml_branches = XML.SubElement(top, 'branchesToPush')
|
||||
for branch in branches:
|
||||
xml_branch = XML.SubElement(
|
||||
xml_branches,
|
||||
'hudson.plugins.git.GitPublisher_-BranchToPush')
|
||||
handle_entity_children(branch['branch'], xml_branch,
|
||||
branch_mappings)
|
||||
|
||||
notes = data.get('notes', [])
|
||||
if notes:
|
||||
xml_notes = XML.SubElement(top, 'notesToPush')
|
||||
for note in notes:
|
||||
xml_note = XML.SubElement(
|
||||
xml_notes,
|
||||
'hudson.plugins.git.GitPublisher_-NoteToPush')
|
||||
handle_entity_children(note['note'], xml_note, note_mappings)
|
||||
|
||||
|
||||
class Publishers(jenkins_jobs.modules.base.Base):
|
||||
sequence = 70
|
||||
|
||||
|
|
1
setup.py
1
setup.py
|
@ -120,6 +120,7 @@ setuptools.setup(
|
|||
'email-ext=jenkins_jobs.modules.publishers:email_ext',
|
||||
'fingerprint=jenkins_jobs.modules.publishers:fingerprint',
|
||||
'ftp=jenkins_jobs.modules.publishers:ftp',
|
||||
'git=jenkins_jobs.modules.publishers:git',
|
||||
('groovy-postbuild=jenkins_jobs.modules.publishers:'
|
||||
'groovy_postbuild'),
|
||||
'html-publisher=jenkins_jobs.modules.publishers:html_publisher',
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
<?xml version="1.0" ?>
|
||||
<project>
|
||||
<publishers>
|
||||
<hudson.plugins.git.GitPublisher>
|
||||
<configVersion>2</configVersion>
|
||||
<pushMerge>true</pushMerge>
|
||||
<pushOnlyIfSuccess>false</pushOnlyIfSuccess>
|
||||
<tagsToPush>
|
||||
<hudson.plugins.git.GitPublisher_-TagToPush>
|
||||
<targetRepoName>tagremotename</targetRepoName>
|
||||
<tagName>tagname</tagName>
|
||||
<tagMessage>some tag message</tagMessage>
|
||||
<createTag>true</createTag>
|
||||
<updateTag>true</updateTag>
|
||||
</hudson.plugins.git.GitPublisher_-TagToPush>
|
||||
</tagsToPush>
|
||||
<branchesToPush>
|
||||
<hudson.plugins.git.GitPublisher_-BranchToPush>
|
||||
<targetRepoName>branchremotename</targetRepoName>
|
||||
<branchName>some/branch</branchName>
|
||||
</hudson.plugins.git.GitPublisher_-BranchToPush>
|
||||
</branchesToPush>
|
||||
<notesToPush>
|
||||
<hudson.plugins.git.GitPublisher_-NoteToPush>
|
||||
<targetRepoName>remotename</targetRepoName>
|
||||
<noteMsg>some note to push</noteMsg>
|
||||
<noteNamespace>notenamespace</noteNamespace>
|
||||
<noteReplace>true</noteReplace>
|
||||
</hudson.plugins.git.GitPublisher_-NoteToPush>
|
||||
</notesToPush>
|
||||
</hudson.plugins.git.GitPublisher>
|
||||
</publishers>
|
||||
</project>
|
|
@ -0,0 +1,22 @@
|
|||
# vim: sw=4 ts=4 et
|
||||
publishers:
|
||||
- git:
|
||||
push-merge: true
|
||||
push-only-if-success: false
|
||||
tags:
|
||||
- tag:
|
||||
remote: tagremotename
|
||||
name: tagname
|
||||
message: "some tag message"
|
||||
create-tag: true
|
||||
update-tag: true
|
||||
branches:
|
||||
- branch:
|
||||
remote: branchremotename
|
||||
name: "some/branch"
|
||||
notes:
|
||||
- note:
|
||||
remote: remotename
|
||||
message: "some note to push"
|
||||
namespace: notenamespace
|
||||
replace-note: true
|
Loading…
Reference in New Issue