Merge "Support for more extensions and options in Git plugin"

This commit is contained in:
Jenkins 2015-07-13 22:43:11 +00:00 committed by Gerrit Code Review
commit d4bff3529d
9 changed files with 264 additions and 22 deletions

View File

@ -3251,6 +3251,7 @@ def git(parser, xml_parent, data):
:arg bool push-only-if-success: Only push to remotes if the build succeeds
- otherwise, nothing will be pushed.
(Default: True)
:arg bool force-push: Add force option to git push (Default: False)
:arg list tags: tags to push at the completion of the build
:tag: * **remote** (`str`) remote repo name to push to
@ -3286,7 +3287,8 @@ def git(parser, xml_parent, data):
:language: yaml
"""
mappings = [('push-merge', 'pushMerge', False),
('push-only-if-success', 'pushOnlyIfSuccess', True)]
('push-only-if-success', 'pushOnlyIfSuccess', True),
('force-push', 'forcePush', False)]
tag_mappings = [('remote', 'targetRepoName', 'origin'),
('name', 'tagName', None),

View File

@ -75,6 +75,11 @@ remoteName/\*')
* **remote** (`string`) - name of repo that contains branch to
merge to (default 'origin')
* **branch** (`string`) - name of the branch to merge to
* **strategy** (`string`) - merge strategy. Can be one of
'default', 'resolve', 'recursive', 'octopus', 'ours',
'subtree'. (default 'default')
* **fast-forward-mode** (`string`) - merge fast-forward mode.
Can be one of 'FF', 'FF_ONLY' or 'NO_FF'. (default 'FF')
:arg str basedir: location relative to the workspace root to clone to
(default: workspace)
:arg bool skip-tag: Skip tagging (default false)
@ -109,6 +114,7 @@ remoteName/\*')
default '0.0')
:arg str project-name: project name in Gitblit and ViewGit repobrowser
(optional)
:arg str repo-name: repository name in phabricator repobrowser (optional)
:arg str choosing-strategy: Jenkins class for selecting what to build
(default 'default')
:arg str git-config-name: Configure name for Git clone (optional)
@ -128,6 +134,17 @@ remoteName/\*')
* **after** (`bool`) - Clean the workspace after checkout
* **before** (`bool`) - Clean the workspace before checkout
:arg list(str) ignore-commits-with-messages: Revisions committed with
messages matching these patterns will be ignored. (optional)
:arg bool force-polling-using-workspace: Force polling using workspace
(default false)
:arg dict sparse-checkout:
:sparse-checkout:
* **paths** (`list`) - List of paths to sparse checkout.
(optional)
:arg dict submodule:
:submodule:
* **disable** (`bool`) - By disabling support for submodules
@ -148,15 +165,22 @@ remoteName/\*')
:browser values:
:auto:
:assemblaweb:
:bitbucketweb:
:cgit:
:fisheye:
:gitblit:
:githubweb:
:gitiles:
:gitlab:
:gitlist:
:gitoriousweb:
:gitweb:
:kiln:
:microsoft-tfs-2013:
:phabricator:
:redmineweb:
:rhodecode:
:stash:
:viewgit:
@ -241,11 +265,23 @@ remoteName/\*')
XML.SubElement(scm, 'excludedRegions').text = exclude_string
if 'merge' in data:
merge = data['merge']
merge_strategies = ['default', 'resolve', 'recursive', 'octopus',
'ours', 'subtree']
fast_forward_modes = ['FF', 'FF_ONLY', 'NO_FF']
name = merge.get('remote', 'origin')
branch = merge['branch']
urc = XML.SubElement(scm, 'userMergeOptions')
XML.SubElement(urc, 'mergeRemote').text = name
XML.SubElement(urc, 'mergeTarget').text = branch
strategy = merge.get('strategy', 'default')
if strategy not in merge_strategies:
raise InvalidAttributeError('strategy', strategy, merge_strategies)
XML.SubElement(urc, 'mergeStrategy').text = strategy
fast_forward_mode = merge.get('fast-forward-mode', 'FF')
if fast_forward_mode not in fast_forward_modes:
raise InvalidAttributeError('fast-forward-mode', fast_forward_mode,
fast_forward_modes)
XML.SubElement(urc, 'fastForwardMode').text = fast_forward_mode
try:
choosing_strategy = choosing_strategies[data.get('choosing-strategy',
@ -285,8 +321,9 @@ remoteName/\*')
XML.SubElement(scm, 'localBranch').text = data['local-branch']
exts_node = XML.SubElement(scm, 'extensions')
impl_prefix = 'hudson.plugins.git.extensions.impl.'
if 'changelog-against' in data:
ext_name = 'hudson.plugins.git.extensions.impl.ChangelogToBranch'
ext_name = impl_prefix + 'ChangelogToBranch'
ext = XML.SubElement(exts_node, ext_name)
opts = XML.SubElement(ext, 'options')
change_remote = data['changelog-against'].get('remote', 'origin')
@ -306,13 +343,28 @@ remoteName/\*')
clean_after = data['clean'].get('after', False)
clean_before = data['clean'].get('before', False)
if clean_after:
ext_name = 'hudson.plugins.git.extensions.impl.CleanCheckout'
ext_name = impl_prefix + 'CleanCheckout'
ext = XML.SubElement(exts_node, ext_name)
if clean_before:
ext_name = 'hudson.plugins.git.extensions.impl.CleanBeforeCheckout'
ext_name = impl_prefix + 'CleanBeforeCheckout'
ext = XML.SubElement(exts_node, ext_name)
if 'ignore-commits-with-messages' in data:
for msg in data['ignore-commits-with-messages']:
ext_name = impl_prefix + 'MessageExclusion'
ext = XML.SubElement(exts_node, ext_name)
XML.SubElement(ext, 'excludedMessage').text = msg
if 'sparse-checkout' in data:
ext_name = impl_prefix + 'SparseCheckoutPaths'
ext = XML.SubElement(exts_node, ext_name)
sparse_co = XML.SubElement(ext, 'sparseCheckoutPaths')
sparse_paths = data['sparse-checkout'].get('paths')
if sparse_paths is not None:
path_tagname = impl_prefix + 'SparseCheckoutPath'
for path in sparse_paths:
path_tag = XML.SubElement(sparse_co, path_tagname)
XML.SubElement(path_tag, 'path').text = path
if 'submodule' in data:
ext_name = 'hudson.plugins.git.extensions.impl.SubmoduleOption'
ext_name = impl_prefix + 'SubmoduleOption'
ext = XML.SubElement(exts_node, ext_name)
XML.SubElement(ext, 'disableSubmodules').text = str(
data['submodule'].get('disable', False)).lower()
@ -323,27 +375,37 @@ remoteName/\*')
XML.SubElement(ext, 'timeout').text = str(
data['submodule'].get('timeout', 10))
if 'timeout' in data:
co = XML.SubElement(exts_node,
'hudson.plugins.git.extensions.impl.'
'CheckoutOption')
co = XML.SubElement(exts_node, impl_prefix + 'CheckoutOption')
XML.SubElement(co, 'timeout').text = str(data['timeout'])
polling_using_workspace = str(data.get('force-polling-using-workspace',
False)).lower()
if polling_using_workspace == 'true':
ext_name = impl_prefix + 'DisableRemotePoll'
ext = XML.SubElement(exts_node, ext_name)
# By default we wipe the workspace
wipe_workspace = str(data.get('wipe-workspace', True)).lower()
if wipe_workspace == 'true':
ext_name = 'hudson.plugins.git.extensions.impl.WipeWorkspace'
ext_name = impl_prefix + 'WipeWorkspace'
ext = XML.SubElement(exts_node, ext_name)
browser = data.get('browser', 'auto')
browserdict = {'auto': 'auto',
'assemblaweb': 'AssemblaWeb',
'bitbucketweb': 'BitbucketWeb',
'cgit': 'CGit',
'fisheye': 'FisheyeGitRepositoryBrowser',
'gitblit': 'GitBlitRepositoryBrowser',
'githubweb': 'GithubWeb',
'gitiles': 'Gitiles',
'gitlab': 'GitLab',
'gitlist': 'GitList',
'gitoriousweb': 'GitoriousWeb',
'gitweb': 'GitWeb',
'kiln': 'KilnGit',
'microsoft-tfs-2013': 'TFS2013GitRepositoryBrowser',
'phabricator': 'Phabricator',
'redmineweb': 'RedmineWeb',
'rhodecode': 'RhodeCode',
'stash': 'Stash',
'viewgit': 'ViewGitWeb'}
if browser not in browserdict:
@ -362,6 +424,9 @@ remoteName/\*')
if browser == 'gitlab':
XML.SubElement(bc, 'version').text = str(
data.get('browser-version', '0.0'))
if browser == 'phabricator':
XML.SubElement(bc, 'repo').text = str(
data.get('repo-name', ''))
def repo(parser, xml_parent, data):

View File

@ -5,6 +5,7 @@
<configVersion>2</configVersion>
<pushMerge>true</pushMerge>
<pushOnlyIfSuccess>false</pushOnlyIfSuccess>
<forcePush>false</forcePush>
<tagsToPush>
<hudson.plugins.git.GitPublisher_-TagToPush>
<targetRepoName>tagremotename</targetRepoName>

View File

@ -0,0 +1,46 @@
<?xml version="1.0" encoding="utf-8"?>
<project>
<scm class="hudson.plugins.git.GitSCM">
<configVersion>2</configVersion>
<userRemoteConfigs>
<hudson.plugins.git.UserRemoteConfig>
<name>origin</name>
<refspec>+refs/heads/*:refs/remotes/origin/*</refspec>
<url>https://github.com/openstack-infra/jenkins-job-builder.git</url>
</hudson.plugins.git.UserRemoteConfig>
</userRemoteConfigs>
<branches>
<hudson.plugins.git.BranchSpec>
<name>**</name>
</hudson.plugins.git.BranchSpec>
</branches>
<excludedUsers/>
<buildChooser class="hudson.plugins.git.util.DefaultBuildChooser"/>
<disableSubmodules>false</disableSubmodules>
<recursiveSubmodules>false</recursiveSubmodules>
<doGenerateSubmoduleConfigurations>false</doGenerateSubmoduleConfigurations>
<authorOrCommitter>false</authorOrCommitter>
<wipeOutWorkspace>true</wipeOutWorkspace>
<pruneBranches>false</pruneBranches>
<remotePoll>false</remotePoll>
<gitTool>Default</gitTool>
<submoduleCfg class="list"/>
<relativeTargetDir/>
<reference/>
<gitConfigName/>
<gitConfigEmail/>
<skipTag>false</skipTag>
<scmName/>
<useShallowClone>false</useShallowClone>
<ignoreNotifyCommit>false</ignoreNotifyCommit>
<extensions>
<hudson.plugins.git.extensions.impl.MessageExclusion>
<excludedMessage>(?s).*FOO.*</excludedMessage>
</hudson.plugins.git.extensions.impl.MessageExclusion>
<hudson.plugins.git.extensions.impl.MessageExclusion>
<excludedMessage>(?s).*BAR.*</excludedMessage>
</hudson.plugins.git.extensions.impl.MessageExclusion>
<hudson.plugins.git.extensions.impl.WipeWorkspace/>
</extensions>
</scm>
</project>

View File

@ -0,0 +1,6 @@
scm:
- git:
url: https://github.com/openstack-infra/jenkins-job-builder.git
ignore-commits-with-messages:
- "(?s).*FOO.*"
- "(?s).*BAR.*"

View File

@ -0,0 +1,53 @@
<?xml version="1.0" encoding="utf-8"?>
<project>
<scm class="hudson.plugins.git.GitSCM">
<configVersion>2</configVersion>
<userRemoteConfigs>
<hudson.plugins.git.UserRemoteConfig>
<name>origin</name>
<refspec>+refs/heads/*:refs/remotes/origin/*</refspec>
<url>https://github.com/openstack-infra/jenkins-job-builder.git</url>
</hudson.plugins.git.UserRemoteConfig>
</userRemoteConfigs>
<branches>
<hudson.plugins.git.BranchSpec>
<name>**</name>
</hudson.plugins.git.BranchSpec>
</branches>
<excludedUsers/>
<buildChooser class="hudson.plugins.git.util.DefaultBuildChooser"/>
<disableSubmodules>false</disableSubmodules>
<recursiveSubmodules>false</recursiveSubmodules>
<doGenerateSubmoduleConfigurations>false</doGenerateSubmoduleConfigurations>
<authorOrCommitter>false</authorOrCommitter>
<wipeOutWorkspace>true</wipeOutWorkspace>
<pruneBranches>false</pruneBranches>
<remotePoll>false</remotePoll>
<gitTool>Default</gitTool>
<submoduleCfg class="list"/>
<relativeTargetDir/>
<reference/>
<gitConfigName/>
<gitConfigEmail/>
<skipTag>false</skipTag>
<scmName/>
<useShallowClone>false</useShallowClone>
<ignoreNotifyCommit>false</ignoreNotifyCommit>
<extensions>
<hudson.plugins.git.extensions.impl.SparseCheckoutPaths>
<sparseCheckoutPaths>
<hudson.plugins.git.extensions.impl.SparseCheckoutPath>
<path>path1</path>
</hudson.plugins.git.extensions.impl.SparseCheckoutPath>
<hudson.plugins.git.extensions.impl.SparseCheckoutPath>
<path>path2</path>
</hudson.plugins.git.extensions.impl.SparseCheckoutPath>
<hudson.plugins.git.extensions.impl.SparseCheckoutPath>
<path>path3</path>
</hudson.plugins.git.extensions.impl.SparseCheckoutPath>
</sparseCheckoutPaths>
</hudson.plugins.git.extensions.impl.SparseCheckoutPaths>
<hudson.plugins.git.extensions.impl.WipeWorkspace/>
</extensions>
</scm>
</project>

View File

@ -0,0 +1,8 @@
scm:
- git:
url: https://github.com/openstack-infra/jenkins-job-builder.git
sparse-checkout:
paths:
- "path1"
- "path2"
- "path3"

View File

@ -0,0 +1,50 @@
<?xml version="1.0" encoding="utf-8"?>
<project>
<scm class="hudson.plugins.git.GitSCM">
<configVersion>2</configVersion>
<userRemoteConfigs>
<hudson.plugins.git.UserRemoteConfig>
<name>origin</name>
<refspec>+refs/heads/*:refs/remotes/origin/*</refspec>
<url>https://github.com/openstack-infra/jenkins-job-builder.git</url>
</hudson.plugins.git.UserRemoteConfig>
</userRemoteConfigs>
<branches>
<hudson.plugins.git.BranchSpec>
<name>**</name>
</hudson.plugins.git.BranchSpec>
</branches>
<excludedUsers/>
<userMergeOptions>
<mergeRemote>repo_name</mergeRemote>
<mergeTarget>branch_name</mergeTarget>
<mergeStrategy>recursive</mergeStrategy>
<fastForwardMode>FF_ONLY</fastForwardMode>
</userMergeOptions>
<buildChooser class="hudson.plugins.git.util.DefaultBuildChooser"/>
<disableSubmodules>false</disableSubmodules>
<recursiveSubmodules>false</recursiveSubmodules>
<doGenerateSubmoduleConfigurations>false</doGenerateSubmoduleConfigurations>
<authorOrCommitter>false</authorOrCommitter>
<wipeOutWorkspace>true</wipeOutWorkspace>
<pruneBranches>false</pruneBranches>
<remotePoll>false</remotePoll>
<gitTool>Default</gitTool>
<submoduleCfg class="list"/>
<relativeTargetDir/>
<reference/>
<gitConfigName/>
<gitConfigEmail/>
<skipTag>false</skipTag>
<scmName/>
<useShallowClone>false</useShallowClone>
<ignoreNotifyCommit>false</ignoreNotifyCommit>
<extensions>
<hudson.plugins.git.extensions.impl.DisableRemotePoll/>
<hudson.plugins.git.extensions.impl.WipeWorkspace/>
</extensions>
<browser class="hudson.plugins.git.browser.RhodeCode">
<url>http://github.com/foo/example.git</url>
</browser>
</scm>
</project>

View File

@ -0,0 +1,11 @@
scm:
- git:
url: https://github.com/openstack-infra/jenkins-job-builder.git
browser: rhodecode
browser-url: http://github.com/foo/example.git
force-polling-using-workspace: true
merge:
remote: repo_name
branch: branch_name
strategy: recursive
fast-forward-mode: FF_ONLY