Add multibranch features
Adds the following features: * discover-pr-forks-strategy * discover-pr-forks-trust * local-branch * checkout-over-ssh * checkout-over-ssh-credentials * filter-by-name-wildcard * filter-by-name-wildcard-include * filter-by-name-wildcard-exclude Change-Id: I475086b73e1e485552279ee7ba03866d610afb07
This commit is contained in:
parent
9f5fc4af8b
commit
c56d688c43
|
@ -313,11 +313,40 @@ def bitbucket_scm(xml_parent, data):
|
||||||
repository is the same as the target repository.
|
repository is the same as the target repository.
|
||||||
Valid options: mergeOnly, headOnly, mergeAndHead.
|
Valid options: mergeOnly, headOnly, mergeAndHead.
|
||||||
Value is not specified by default.
|
Value is not specified by default.
|
||||||
|
:arg str discover-pr-forks-strategy: Fork strategy. Valid options:
|
||||||
|
merge-current, current, both, false. (default 'merge-current')
|
||||||
|
:arg str discover-pr-forks-trust: Discovers pull requests where the origin
|
||||||
|
repository is a fork of the target repository.
|
||||||
|
Valid options: contributors, everyone, permission or nobody.
|
||||||
|
(default 'contributors')
|
||||||
:arg list build-strategies: Provides control over whether to build a branch
|
:arg list build-strategies: Provides control over whether to build a branch
|
||||||
(or branch like things such as change requests and tags) whenever it is
|
(or branch like things such as change requests and tags) whenever it is
|
||||||
discovered initially or a change from the previous revision has been
|
discovered initially or a change from the previous revision has been
|
||||||
detected. (optional)
|
detected. (optional)
|
||||||
Refer to :func:`~build_strategies <build_strategies>`.
|
Refer to :func:`~build_strategies <build_strategies>`.
|
||||||
|
:arg bool local-branch: Check out to matching local branch
|
||||||
|
If given, checkout the revision to build as HEAD on this branch.
|
||||||
|
If selected, then the branch name is computed from the remote branch
|
||||||
|
without the origin. In that case, a remote branch origin/master will
|
||||||
|
be checked out to a local branch named master, and a remote branch
|
||||||
|
origin/develop/new-feature will be checked out to a local branch
|
||||||
|
named develop/newfeature.
|
||||||
|
Requires the :jenkins-wiki:`Git Plugin <Git+Plugin>`.
|
||||||
|
:arg dict checkout-over-ssh: Checkout repo over ssh.
|
||||||
|
|
||||||
|
* **credentials** ('str'): Credentials to use for
|
||||||
|
checkout of the repo over ssh.
|
||||||
|
|
||||||
|
:arg dict filter-by-name-wildcard: Enable filter by name with wildcards.
|
||||||
|
Requires the :jenkins-wiki:`SCM API Plugin <SCM+API+Plugin>`.
|
||||||
|
|
||||||
|
* **includes** ('str'): Space-separated list
|
||||||
|
of name patterns to consider. You may use * as a wildcard;
|
||||||
|
for example: `master release*`
|
||||||
|
* **excludes** ('str'): Name patterns to
|
||||||
|
ignore even if matched by the includes list.
|
||||||
|
For example: `release*`
|
||||||
|
|
||||||
|
|
||||||
Minimal Example:
|
Minimal Example:
|
||||||
|
|
||||||
|
@ -373,6 +402,43 @@ def bitbucket_scm(xml_parent, data):
|
||||||
helpers.convert_mapping_to_xml(
|
helpers.convert_mapping_to_xml(
|
||||||
dpro, data, dpro_mapping, fail_required=True)
|
dpro, data, dpro_mapping, fail_required=True)
|
||||||
|
|
||||||
|
if data.get('discover-pr-forks-strategy'):
|
||||||
|
dprf = XML.SubElement(traits,
|
||||||
|
'com.cloudbees.jenkins.plugins.bitbucket'
|
||||||
|
'.ForkPullRequestDiscoveryTrait')
|
||||||
|
dprf_strategy = {
|
||||||
|
'merge-current': '1',
|
||||||
|
'current': '2',
|
||||||
|
'both': '3',
|
||||||
|
}
|
||||||
|
dprf_mapping = [
|
||||||
|
('discover-pr-forks-strategy', 'strategyId', 'merge-current',
|
||||||
|
dprf_strategy)
|
||||||
|
]
|
||||||
|
helpers.convert_mapping_to_xml(
|
||||||
|
dprf, data, dprf_mapping, fail_required=True)
|
||||||
|
|
||||||
|
trust = data.get('discover-pr-forks-trust', 'contributors')
|
||||||
|
trust_map = {
|
||||||
|
'contributors': ''.join([
|
||||||
|
'com.cloudbees.jenkins.plugins.bitbucket'
|
||||||
|
'.ForkPullRequestDiscoveryTrait$TrustContributors']),
|
||||||
|
'everyone': ''.join([
|
||||||
|
'com.cloudbees.jenkins.plugins.bitbucket'
|
||||||
|
'.ForkPullRequestDiscoveryTrait$TrustEveryone']),
|
||||||
|
'permission': ''.join([
|
||||||
|
'com.cloudbees.jenkins.plugins.bitbucket'
|
||||||
|
'.ForkPullRequestDiscoveryTrait$TrustPermission']),
|
||||||
|
'nobody': ''.join([
|
||||||
|
'com.cloudbees.jenkins.plugins.bitbucket'
|
||||||
|
'.ForkPullRequestDiscoveryTrait$TrustNobody']),
|
||||||
|
}
|
||||||
|
if trust not in trust_map:
|
||||||
|
raise InvalidAttributeError('discover-pr-forks-trust',
|
||||||
|
trust,
|
||||||
|
trust_map.keys())
|
||||||
|
XML.SubElement(dprf, 'trust').attrib['class'] = trust_map[trust]
|
||||||
|
|
||||||
if data.get('discover-branch', None):
|
if data.get('discover-branch', None):
|
||||||
dbr = XML.SubElement(traits,
|
dbr = XML.SubElement(traits,
|
||||||
'com.cloudbees.jenkins.plugins.bitbucket.BranchDiscoveryTrait')
|
'com.cloudbees.jenkins.plugins.bitbucket.BranchDiscoveryTrait')
|
||||||
|
@ -390,6 +456,48 @@ def bitbucket_scm(xml_parent, data):
|
||||||
if data.get('build-strategies', None):
|
if data.get('build-strategies', None):
|
||||||
build_strategies(xml_parent, data)
|
build_strategies(xml_parent, data)
|
||||||
|
|
||||||
|
if data.get('local-branch', False):
|
||||||
|
lbr = XML.SubElement(traits,
|
||||||
|
'jenkins.plugins.git.traits.LocalBranchTrait', {
|
||||||
|
'plugin': 'git',
|
||||||
|
}
|
||||||
|
)
|
||||||
|
lbr_extension = XML.SubElement(lbr,
|
||||||
|
'extension', {
|
||||||
|
'class': 'hudson.plugins.git.extensions.impl.LocalBranch',
|
||||||
|
}
|
||||||
|
)
|
||||||
|
XML.SubElement(lbr_extension,
|
||||||
|
'localBranch').text = "**"
|
||||||
|
|
||||||
|
if data.get('checkout-over-ssh', None):
|
||||||
|
cossh = XML.SubElement(traits,
|
||||||
|
'com.cloudbees.jenkins.plugins.bitbucket.SSHCheckoutTrait')
|
||||||
|
cossh_credentials = [
|
||||||
|
('credentials', 'credentialsId', ''),
|
||||||
|
]
|
||||||
|
helpers.convert_mapping_to_xml(
|
||||||
|
cossh,
|
||||||
|
data.get('checkout-over-ssh'),
|
||||||
|
cossh_credentials,
|
||||||
|
fail_required=True)
|
||||||
|
|
||||||
|
if data.get('filter-by-name-wildcard', None):
|
||||||
|
wscmf_name = XML.SubElement(traits,
|
||||||
|
'jenkins.scm.impl.trait.WildcardSCMHeadFilterTrait', {
|
||||||
|
'plugin': 'scm-api',
|
||||||
|
}
|
||||||
|
)
|
||||||
|
wscmf_name_mapping = [
|
||||||
|
('includes', 'includes', ''),
|
||||||
|
('excludes', 'excludes', '')
|
||||||
|
]
|
||||||
|
helpers.convert_mapping_to_xml(
|
||||||
|
wscmf_name,
|
||||||
|
data.get('filter-by-name-wildcard', ''),
|
||||||
|
wscmf_name_mapping,
|
||||||
|
fail_required=True)
|
||||||
|
|
||||||
|
|
||||||
def gerrit_scm(xml_parent, data):
|
def gerrit_scm(xml_parent, data):
|
||||||
"""Configure Gerrit SCM
|
"""Configure Gerrit SCM
|
||||||
|
|
|
@ -45,9 +45,25 @@
|
||||||
<com.cloudbees.jenkins.plugins.bitbucket.OriginPullRequestDiscoveryTrait>
|
<com.cloudbees.jenkins.plugins.bitbucket.OriginPullRequestDiscoveryTrait>
|
||||||
<strategyId>2</strategyId>
|
<strategyId>2</strategyId>
|
||||||
</com.cloudbees.jenkins.plugins.bitbucket.OriginPullRequestDiscoveryTrait>
|
</com.cloudbees.jenkins.plugins.bitbucket.OriginPullRequestDiscoveryTrait>
|
||||||
|
<com.cloudbees.jenkins.plugins.bitbucket.ForkPullRequestDiscoveryTrait>
|
||||||
|
<strategyId>2</strategyId>
|
||||||
|
<trust class="com.cloudbees.jenkins.plugins.bitbucket.ForkPullRequestDiscoveryTrait$TrustEveryone"/>
|
||||||
|
</com.cloudbees.jenkins.plugins.bitbucket.ForkPullRequestDiscoveryTrait>
|
||||||
<com.cloudbees.jenkins.plugins.bitbucket.BranchDiscoveryTrait>
|
<com.cloudbees.jenkins.plugins.bitbucket.BranchDiscoveryTrait>
|
||||||
<strategyId>3</strategyId>
|
<strategyId>3</strategyId>
|
||||||
</com.cloudbees.jenkins.plugins.bitbucket.BranchDiscoveryTrait>
|
</com.cloudbees.jenkins.plugins.bitbucket.BranchDiscoveryTrait>
|
||||||
|
<jenkins.plugins.git.traits.LocalBranchTrait plugin="git">
|
||||||
|
<extension class="hudson.plugins.git.extensions.impl.LocalBranch">
|
||||||
|
<localBranch>**</localBranch>
|
||||||
|
</extension>
|
||||||
|
</jenkins.plugins.git.traits.LocalBranchTrait>
|
||||||
|
<com.cloudbees.jenkins.plugins.bitbucket.SSHCheckoutTrait>
|
||||||
|
<credentialsId>ssh_secret</credentialsId>
|
||||||
|
</com.cloudbees.jenkins.plugins.bitbucket.SSHCheckoutTrait>
|
||||||
|
<jenkins.scm.impl.trait.WildcardSCMHeadFilterTrait plugin="scm-api">
|
||||||
|
<includes>*</includes>
|
||||||
|
<excludes>master</excludes>
|
||||||
|
</jenkins.scm.impl.trait.WildcardSCMHeadFilterTrait>
|
||||||
</traits>
|
</traits>
|
||||||
</source>
|
</source>
|
||||||
<buildStrategies>
|
<buildStrategies>
|
||||||
|
|
|
@ -11,6 +11,14 @@ scm:
|
||||||
head-filter-regex: 'master|\d+\.\d+'
|
head-filter-regex: 'master|\d+\.\d+'
|
||||||
discover-pr-origin: headOnly
|
discover-pr-origin: headOnly
|
||||||
discover-branch: all
|
discover-branch: all
|
||||||
|
discover-pr-forks-strategy: current
|
||||||
|
discover-pr-forks-trust: everyone
|
||||||
|
local-branch: true
|
||||||
|
checkout-over-ssh:
|
||||||
|
credentials: 'ssh_secret'
|
||||||
|
filter-by-name-wildcard:
|
||||||
|
includes: '*'
|
||||||
|
excludes: 'master'
|
||||||
build-strategies:
|
build-strategies:
|
||||||
- tags:
|
- tags:
|
||||||
ignore-tags-newer-than: 1
|
ignore-tags-newer-than: 1
|
||||||
|
|
Loading…
Reference in New Issue