コード例 #1
0
def git_scm(xml_parent, data):
    """Configure Git SCM

    Requires the :jenkins-wiki:`Git Plugin <Git+Plugin>`.

    :arg str url: The git repo url. (required)
    :arg str credentials-id: The credential to use to connect to the GIT repo.
        (default '')

    :arg bool discover-branches: Discovers branches on the repository.
        (default true)
    :arg bool discover-tags: Discovers tags on the repository.
        (default false)
    :arg bool ignore-on-push-notifications: If a job should not trigger upon
        push notifications. (default false)
    :arg str head-filter-regex: A regular expression for filtering
        discovered source branches. Requires the :jenkins-wiki:`SCM API Plugin
        <SCM+API+Plugin>`.
    :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
        discovered initially or a change from the previous revision has been
        detected. (optional)
        Refer to :func:`~build_strategies <build_strategies>`.

    :extensions:

        * **clean** (`dict`)
            * **after** (`bool`) - Clean the workspace after checkout
            * **before** (`bool`) - Clean the workspace before checkout
        * **prune** (`bool`) - Prune remote branches (default false)
        * **shallow-clone** (`bool`) - Perform shallow clone (default false)
        * **depth** (`int`) - Set shallow clone depth (default 1)
        * **do-not-fetch-tags** (`bool`) - Perform a clone without tags
            (default false)
        * **submodule** (`dict`)
            * **disable** (`bool`) - By disabling support for submodules you
              can still keep using basic git plugin functionality and just have
              Jenkins to ignore submodules completely as if they didn't exist.
            * **recursive** (`bool`) - Retrieve all submodules recursively
              (uses '--recursive' option which requires git>=1.6.5)
            * **tracking** (`bool`) - Retrieve the tip of the configured
              branch in .gitmodules (Uses '\-\-remote' option which requires
              git>=1.8.2)
            * **parent-credentials** (`bool`) - Use credentials from default
              remote of parent repository (default false).
            * **reference-repo** (`str`) - Path of the reference repo to use
              during clone (optional)
            * **timeout** (`int`) - Specify a timeout (in minutes) for
              submodules operations (default 10).
        * **timeout** (`str`) - Timeout for git commands in minutes (optional)
        * **use-author** (`bool`): Use author rather than committer in Jenkin's
            build changeset (default false)
        * **wipe-workspace** (`bool`) - Wipe out workspace before build
            (default true)

    Minimal Example:

    .. literalinclude:: /../../tests/multibranch/fixtures/scm_git_minimal.yaml

    Full Example:

    .. literalinclude:: /../../tests/multibranch/fixtures/scm_git_full.yaml
    """
    source = XML.SubElement(xml_parent, 'source', {
        'class': 'jenkins.plugins.git.GitSCMSource',
        'plugin': 'git',
    })
    source_mapping = [
        ('', 'id', '-'.join(['gt', data.get('url', '')])),
        ('url', 'remote', None),
        ('credentials-id', 'credentialsId', ''),
    ]
    helpers.convert_mapping_to_xml(
        source, data, source_mapping, fail_required=True)

    ##########
    # Traits #
    ##########

    traits_path = 'jenkins.plugins.git.traits'
    traits = XML.SubElement(source, 'traits')

    if data.get('discover-branches', True):
        XML.SubElement(traits, ''.join([traits_path, '.BranchDiscoveryTrait']))

    if data.get('discover-tags', False):
        XML.SubElement(traits, ''.join([traits_path, '.TagDiscoveryTrait']))

    if data.get('ignore-on-push-notifications', False):
        XML.SubElement(
            traits, ''.join([traits_path, '.IgnoreOnPushNotificationTrait']))

    if data.get('head-filter-regex', None):
        rshf = XML.SubElement(traits,
            'jenkins.scm.impl.trait.RegexSCMHeadFilterTrait')
        XML.SubElement(rshf, 'regex').text = data.get('head-filter-regex')

    if data.get('build-strategies', None):
        build_strategies(xml_parent, data)

    # handle the default git extensions like:
    # - clean
    # - shallow-clone
    # - timeout
    # - do-not-fetch-tags
    # - submodule
    # - prune
    # - wipe-workspace
    # - use-author
    git_extensions(traits, data)
コード例 #2
0
def github_scm(xml_parent, data):
    """Configure GitHub SCM

    Requires the :jenkins-wiki:`GitHub Branch Source Plugin
    <GitHub+Branch+Source+Plugin>`.

    :arg str api-uri: The GitHub API uri for hosted / on-site GitHub. Must
        first be configured in Global Configuration. (default GitHub)
    :arg bool ssh-checkout: Checkout over SSH. (default false)
    :arg str credentials-id: Credentials used to scan branches and pull
        requests, check out sources and mark commit statuses. (optional)
    :arg str repo-owner: Specify the name of the GitHub Organization or
        GitHub User Account. (required)
    :arg str repo: The GitHub repo. (required)

    :arg str branch-discovery: Discovers branches on the repository.
        Valid options: no-pr, only-pr, all, false. (default 'no-pr')
    :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 str discover-pr-origin: Discovers pull requests where the origin
        repository is the same as the target repository.
        Valid options: merge-current, current, both.  (default 'merge-current')
    :arg bool discover-tags: Discovers tags on the repository.
        (default false)
    :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
        discovered initially or a change from the previous revision has been
        detected. (optional)
        Refer to :func:`~build_strategies <build_strategies>`.

    :extensions:

        * **clean** (`dict`)
            * **after** (`bool`) - Clean the workspace after checkout
            * **before** (`bool`) - Clean the workspace before checkout
        * **prune** (`bool`) - Prune remote branches (default false)
        * **shallow-clone** (`bool`) - Perform shallow clone (default false)
        * **depth** (`int`) - Set shallow clone depth (default 1)
        * **do-not-fetch-tags** (`bool`) - Perform a clone without tags
            (default false)
        * **submodule** (`dict`)
            * **disable** (`bool`) - By disabling support for submodules you
              can still keep using basic git plugin functionality and just have
              Jenkins to ignore submodules completely as if they didn't exist.
            * **recursive** (`bool`) - Retrieve all submodules recursively
              (uses '--recursive' option which requires git>=1.6.5)
            * **tracking** (`bool`) - Retrieve the tip of the configured
              branch in .gitmodules (Uses '\-\-remote' option which requires
              git>=1.8.2)
            * **parent-credentials** (`bool`) - Use credentials from default
              remote of parent repository (default false).
            * **reference-repo** (`str`) - Path of the reference repo to use
              during clone (optional)
            * **timeout** (`int`) - Specify a timeout (in minutes) for
              submodules operations (default 10).
        * **timeout** (`str`) - Timeout for git commands in minutes (optional)
        * **use-author** (`bool`): Use author rather than committer in Jenkin's
            build changeset (default false)
        * **wipe-workspace** (`bool`) - Wipe out workspace before build
            (default true)

    Minimal Example:

    .. literalinclude::
       /../../tests/multibranch/fixtures/scm_github_minimal.yaml

    Full Example:

    .. literalinclude::
       /../../tests/multibranch/fixtures/scm_github_full.yaml
    """
    github_path = 'org.jenkinsci.plugins.github_branch_source'
    github_path_dscore = 'org.jenkinsci.plugins.github__branch__source'

    source = XML.SubElement(xml_parent, 'source', {
        'class': ''.join([github_path, '.GitHubSCMSource']),
        'plugin': 'github-branch-source',
    })
    mapping = [
        ('', 'id', '-'.join(['gh', data.get('repo-owner', ''),
            data.get('repo', '')])),
        ('repo-owner', 'repoOwner', None),
        ('repo', 'repository', None),
    ]
    helpers.convert_mapping_to_xml(
        source, data, mapping, fail_required=True)

    mapping_optional = [
        ('api-uri', 'apiUri', None),
        ('credentials-id', 'credentialsId', None),
    ]
    helpers.convert_mapping_to_xml(
        source, data, mapping_optional, fail_required=False)

    traits = XML.SubElement(source, 'traits')

    # no-pr value is assumed if branch-discovery not mentioned.
    if data.get('branch-discovery', 'no-pr'):
        bd = XML.SubElement(traits, ''.join([
            github_path_dscore, '.BranchDiscoveryTrait']))
        bd_strategy = {
            'no-pr': '1',
            'only-pr': '2',
            'all': '3',
        }
        bd_mapping = [
            ('branch-discovery', 'strategyId', 'no-pr', bd_strategy)
        ]
        helpers.convert_mapping_to_xml(
            bd, data, bd_mapping, fail_required=True)

    if data.get('ssh-checkout', False):
        XML.SubElement(
            traits, ''.join([
                github_path_dscore, '.SSHCheckoutTrait'
            ])
        )

    if data.get('discover-tags', False):
        XML.SubElement(
            traits, ''.join([
                github_path_dscore, '.TagDiscoveryTrait'
            ])
        )

    if data.get('discover-pr-forks-strategy', 'merged-current'):
        dprf = XML.SubElement(
            traits, ''.join([
                github_path_dscore, '.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([
                github_path,
                '.ForkPullRequestDiscoveryTrait$TrustContributors']),
            'everyone': ''.join([
                github_path,
                '.ForkPullRequestDiscoveryTrait$TrustEveryone']),
            'permission': ''.join([
                github_path,
                '.ForkPullRequestDiscoveryTrait$TrustPermission']),
            'nobody': ''.join([
                github_path,
                '.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]

    dpro_strategy = data.get('discover-pr-origin', 'merge-current')
    dpro = XML.SubElement(traits, ''.join([
        github_path_dscore,
        '.OriginPullRequestDiscoveryTrait'
    ]))
    dpro_strategy_map = {
        'merge-current': '1',
        'current': '2',
        'both': '3',
    }
    if dpro_strategy not in dpro_strategy_map:
        raise InvalidAttributeError('discover-pr-origin',
                                    dpro_strategy,
                                    dpro_strategy_map.keys())
    dpro_mapping = [
        ('discover-pr-origin', 'strategyId', 'merge-current',
        dpro_strategy_map)
    ]
    helpers.convert_mapping_to_xml(
        dpro, data, dpro_mapping, fail_required=True)

    if data.get('build-strategies', None):
        build_strategies(xml_parent, data)

    # handle the default git extensions like:
    # - clean
    # - shallow-clone
    # - timeout
    # - do-not-fetch-tags
    # - submodule
    # - prune
    # - wipe-workspace
    # - use-author
    git_extensions(traits, data)
コード例 #3
0
def bitbucket_scm(xml_parent, data):
    """Configure BitBucket scm

    Requires the :jenkins-wiki:`Bitbucket Branch Source Plugin
    <Bitbucket+Branch+Source+Plugin>`.

    :arg str credentials-id: The credential to use to scan BitBucket.
        (required)
    :arg str repo-owner: Specify the name of the Bitbucket Team or Bitbucket
        User Account. (required)
    :arg str repo: The BitBucket repo. (required)

    :arg bool discover-tags: Discovers tags on the repository.
        (default false)
    :arg str server-url: The address of the bitbucket server. (optional)
    :arg str head-filter-regex: A regular expression for filtering
        discovered source branches. Requires the :jenkins-wiki:`SCM API Plugin
        <SCM+API+Plugin>`.
    :arg str discovery-branch: Discovers branches on the repository.
        Valid options: ex-pr, only-pr, all.
        Value is not specified by default.
    :arg str discover-pr-origin: Discovers pull requests where the origin
        repository is the same as the target repository.
        Valid options: mergeOnly, headOnly, mergeAndHead.
        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
        (or branch like things such as change requests and tags) whenever it is
        discovered initially or a change from the previous revision has been
        detected. (optional)
        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*`

    :extensions:

        * **clean** (`dict`)
            * **after** (`bool`) - Clean the workspace after checkout
            * **before** (`bool`) - Clean the workspace before checkout
        * **prune** (`bool`) - Prune remote branches (default false)
        * **shallow-clone** (`bool`) - Perform shallow clone (default false)
        * **depth** (`int`) - Set shallow clone depth (default 1)
        * **do-not-fetch-tags** (`bool`) - Perform a clone without tags
            (default false)
        * **submodule** (`dict`)
            * **disable** (`bool`) - By disabling support for submodules you
              can still keep using basic git plugin functionality and just have
              Jenkins to ignore submodules completely as if they didn't exist.
            * **recursive** (`bool`) - Retrieve all submodules recursively
              (uses '--recursive' option which requires git>=1.6.5)
            * **tracking** (`bool`) - Retrieve the tip of the configured
              branch in .gitmodules (Uses '\-\-remote' option which requires
              git>=1.8.2)
            * **parent-credentials** (`bool`) - Use credentials from default
              remote of parent repository (default false).
            * **reference-repo** (`str`) - Path of the reference repo to use
              during clone (optional)
            * **timeout** (`int`) - Specify a timeout (in minutes) for
              submodules operations (default 10).
        * **timeout** (`str`) - Timeout for git commands in minutes (optional)
        * **use-author** (`bool`): Use author rather than committer in Jenkin's
            build changeset (default false)
        * **wipe-workspace** (`bool`) - Wipe out workspace before build
            (default true)


    Minimal Example:

    .. literalinclude::
       /../../tests/multibranch/fixtures/scm_bitbucket_minimal.yaml

    Full Example:

    .. literalinclude::
       /../../tests/multibranch/fixtures/scm_bitbucket_full.yaml
    """
    source = XML.SubElement(xml_parent, 'source', {
        'class': 'com.cloudbees.jenkins.plugins.bitbucket.BitbucketSCMSource',
        'plugin': 'cloudbees-bitbucket-branch-source',
    })
    source_mapping = [
        ('', 'id', '-'.join(['bb', data.get('repo-owner', ''),
            data.get('repo', '')])),
        ('repo-owner', 'repoOwner', None),
        ('repo', 'repository', None),
    ]
    helpers.convert_mapping_to_xml(
        source, data, source_mapping, fail_required=True)

    mapping_optional = [
        ('credentials-id', 'credentialsId', None),
        ('server-url', 'serverUrl', None),
    ]
    helpers.convert_mapping_to_xml(
        source, data, mapping_optional, fail_required=False)

    traits = XML.SubElement(source, 'traits')
    if data.get('discover-tags', False):
        XML.SubElement(traits,
            'com.cloudbees.jenkins.plugins.bitbucket.TagDiscoveryTrait')
    if data.get('head-filter-regex', None):
        rshf = XML.SubElement(traits,
            'jenkins.scm.impl.trait.RegexSCMHeadFilterTrait')
        XML.SubElement(rshf, 'regex').text = data.get('head-filter-regex')

    if data.get('discover-pr-origin', None):
        dpro = XML.SubElement(traits,
            'com.cloudbees.jenkins.plugins.bitbucket'
            '.OriginPullRequestDiscoveryTrait')
        dpro_strategies = {
            'mergeOnly': '1',
            'headOnly': '2',
            'mergeAndHead': '3'
        }
        dpro_mapping = [
            ('discover-pr-origin', 'strategyId', None, dpro_strategies)
        ]
        helpers.convert_mapping_to_xml(
            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):
        dbr = XML.SubElement(traits,
            'com.cloudbees.jenkins.plugins.bitbucket.BranchDiscoveryTrait')
        dbr_strategies = {
            'ex-pr': '1',
            'only-pr': '2',
            'all': '3'
        }
        dbr_mapping = [
            ('discover-branch', 'strategyId', None, dbr_strategies)
        ]
        helpers.convert_mapping_to_xml(
            dbr, data, dbr_mapping, fail_required=True)

    if data.get('build-strategies', None):
        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)

    # handle the default git extensions like:
    # - clean
    # - shallow-clone
    # - timeout
    # - do-not-fetch-tags
    # - submodule
    # - prune
    # - wipe-workspace
    # - use-author
    git_extensions(traits, data)
コード例 #4
0
def github_scm(xml_parent, data):
    r"""Configure GitHub SCM

    Requires the :jenkins-wiki:`GitHub Branch Source Plugin
    <GitHub+Branch+Source+Plugin>`.

    :arg str api-uri: The GitHub API uri for hosted / on-site GitHub. Must
        first be configured in Global Configuration. (default GitHub)
    :arg bool ssh-checkout: Checkout over SSH.

        * **credentials** ('str'): Credentials to use for
            checkout of the repo over ssh.

    :arg str credentials-id: Credentials used to scan branches and pull
        requests, check out sources and mark commit statuses. (optional)
    :arg str repo-owner: Specify the name of the GitHub Organization or
        GitHub User Account. (required)
    :arg str repo: The GitHub repo. (required)

    :arg str branch-discovery: Discovers branches on the repository.
        Valid options: no-pr, only-pr, all, false. (default 'no-pr')
    :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 str discover-pr-origin: Discovers pull requests where the origin
        repository is the same as the target repository.
        Valid options: merge-current, current, both.  (default 'merge-current')
    :arg bool discover-tags: Discovers tags on the repository.
        (default false)
    :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
        discovered initially or a change from the previous revision has been
        detected. (optional)
        Refer to :func:`~build_strategies <build_strategies>`.

    :extensions:

        * **clean** (`dict`)
            * **after** (`bool`) - Clean the workspace after checkout
            * **before** (`bool`) - Clean the workspace before checkout
        * **prune** (`bool`) - Prune remote branches (default false)
        * **shallow-clone** (`bool`) - Perform shallow clone (default false)
        * **depth** (`int`) - Set shallow clone depth (default 1)
        * **do-not-fetch-tags** (`bool`) - Perform a clone without tags
            (default false)
        * **submodule** (`dict`)
            * **disable** (`bool`) - By disabling support for submodules you
              can still keep using basic git plugin functionality and just have
              Jenkins to ignore submodules completely as if they didn't exist.
            * **recursive** (`bool`) - Retrieve all submodules recursively
              (uses '--recursive' option which requires git>=1.6.5)
            * **tracking** (`bool`) - Retrieve the tip of the configured
              branch in .gitmodules (Uses '\-\-remote' option which requires
              git>=1.8.2)
            * **parent-credentials** (`bool`) - Use credentials from default
              remote of parent repository (default false).
            * **reference-repo** (`str`) - Path of the reference repo to use
              during clone (optional)
            * **timeout** (`int`) - Specify a timeout (in minutes) for
              submodules operations (default 10).
        * **timeout** (`str`) - Timeout for git commands in minutes (optional)
        * **use-author** (`bool`): Use author rather than committer in Jenkin's
            build changeset (default false)
        * **wipe-workspace** (`bool`) - Wipe out workspace before build
            (default true)

    Minimal Example:

    .. literalinclude::
       /../../tests/multibranch/fixtures/scm_github_minimal.yaml

    Full Example:

    .. literalinclude::
       /../../tests/multibranch/fixtures/scm_github_full.yaml
    """
    github_path = 'org.jenkinsci.plugins.github_branch_source'
    github_path_dscore = 'org.jenkinsci.plugins.github__branch__source'

    source = XML.SubElement(
        xml_parent, 'source', {
            'class': ''.join([github_path, '.GitHubSCMSource']),
            'plugin': 'github-branch-source',
        })
    mapping = [
        ('', 'id',
         '-'.join(['gh',
                   data.get('repo-owner', ''),
                   data.get('repo', '')])),
        ('repo-owner', 'repoOwner', None),
        ('repo', 'repository', None),
    ]
    helpers.convert_mapping_to_xml(source, data, mapping, fail_required=True)

    mapping_optional = [
        ('api-uri', 'apiUri', None),
        ('credentials-id', 'credentialsId', None),
    ]
    helpers.convert_mapping_to_xml(source,
                                   data,
                                   mapping_optional,
                                   fail_required=False)

    traits = XML.SubElement(source, 'traits')

    # no-pr value is assumed if branch-discovery not mentioned.
    if data.get('branch-discovery', 'no-pr'):
        bd = XML.SubElement(
            traits, ''.join([github_path_dscore, '.BranchDiscoveryTrait']))
        bd_strategy = {
            'no-pr': '1',
            'only-pr': '2',
            'all': '3',
        }
        bd_mapping = [('branch-discovery', 'strategyId', 'no-pr', bd_strategy)]
        helpers.convert_mapping_to_xml(bd,
                                       data,
                                       bd_mapping,
                                       fail_required=True)

    if data.get('ssh-checkout', None):
        cossh = XML.SubElement(
            traits, ''.join([github_path_dscore, '.SSHCheckoutTrait']))
        if not isinstance(data.get('ssh-checkout'), bool):
            cossh_credentials = [
                ('credentials', 'credentialsId', ''),
            ]
            helpers.convert_mapping_to_xml(cossh,
                                           data.get('ssh-checkout'),
                                           cossh_credentials,
                                           fail_required=True)

    if data.get('discover-tags', False):
        XML.SubElement(traits,
                       ''.join([github_path_dscore, '.TagDiscoveryTrait']))

    if data.get('discover-pr-forks-strategy', 'merged-current'):
        dprf = XML.SubElement(
            traits,
            ''.join([github_path_dscore, '.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([
                github_path, '.ForkPullRequestDiscoveryTrait$TrustContributors'
            ]),
            'everyone':
            ''.join(
                [github_path, '.ForkPullRequestDiscoveryTrait$TrustEveryone']),
            'permission':
            ''.join([
                github_path, '.ForkPullRequestDiscoveryTrait$TrustPermission'
            ]),
            'nobody':
            ''.join(
                [github_path, '.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]

    dpro_strategy = data.get('discover-pr-origin', 'merge-current')
    dpro = XML.SubElement(
        traits,
        ''.join([github_path_dscore, '.OriginPullRequestDiscoveryTrait']))
    dpro_strategy_map = {
        'merge-current': '1',
        'current': '2',
        'both': '3',
    }
    if dpro_strategy not in dpro_strategy_map:
        raise InvalidAttributeError('discover-pr-origin', dpro_strategy,
                                    dpro_strategy_map.keys())
    dpro_mapping = [('discover-pr-origin', 'strategyId', 'merge-current',
                     dpro_strategy_map)]
    helpers.convert_mapping_to_xml(dpro,
                                   data,
                                   dpro_mapping,
                                   fail_required=True)

    if data.get('build-strategies', None):
        build_strategies(xml_parent, data)

    # handle the default git extensions like:
    # - clean
    # - shallow-clone
    # - timeout
    # - do-not-fetch-tags
    # - submodule
    # - prune
    # - wipe-workspace
    # - use-author
    git_extensions(traits, data)
コード例 #5
0
def git_scm(xml_parent, data):
    r"""Configure Git SCM

    Requires the :jenkins-wiki:`Git Plugin <Git+Plugin>`.

    :arg str url: The git repo url. (required)
    :arg str credentials-id: The credential to use to connect to the GIT repo.
        (default '')

    :arg bool discover-branches: Discovers branches on the repository.
        (default true)
    :arg bool discover-tags: Discovers tags on the repository.
        (default false)
    :arg bool ignore-on-push-notifications: If a job should not trigger upon
        push notifications. (default false)
    :arg str head-filter-regex: A regular expression for filtering
        discovered source branches. Requires the :jenkins-wiki:`SCM API Plugin
        <SCM+API+Plugin>`.
    :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
        discovered initially or a change from the previous revision has been
        detected. (optional)
        Refer to :func:`~build_strategies <build_strategies>`.

    :extensions:

        * **clean** (`dict`)
            * **after** (`bool`) - Clean the workspace after checkout
            * **before** (`bool`) - Clean the workspace before checkout
        * **prune** (`bool`) - Prune remote branches (default false)
        * **shallow-clone** (`bool`) - Perform shallow clone (default false)
        * **depth** (`int`) - Set shallow clone depth (default 1)
        * **do-not-fetch-tags** (`bool`) - Perform a clone without tags
            (default false)
        * **submodule** (`dict`)
            * **disable** (`bool`) - By disabling support for submodules you
              can still keep using basic git plugin functionality and just have
              Jenkins to ignore submodules completely as if they didn't exist.
            * **recursive** (`bool`) - Retrieve all submodules recursively
              (uses '--recursive' option which requires git>=1.6.5)
            * **tracking** (`bool`) - Retrieve the tip of the configured
              branch in .gitmodules (Uses '\-\-remote' option which requires
              git>=1.8.2)
            * **parent-credentials** (`bool`) - Use credentials from default
              remote of parent repository (default false).
            * **reference-repo** (`str`) - Path of the reference repo to use
              during clone (optional)
            * **timeout** (`int`) - Specify a timeout (in minutes) for
              submodules operations (default 10).
        * **timeout** (`str`) - Timeout for git commands in minutes (optional)
        * **use-author** (`bool`): Use author rather than committer in Jenkin's
            build changeset (default false)
        * **wipe-workspace** (`bool`) - Wipe out workspace before build
            (default true)

    Minimal Example:

    .. literalinclude:: /../../tests/multibranch/fixtures/scm_git_minimal.yaml

    Full Example:

    .. literalinclude:: /../../tests/multibranch/fixtures/scm_git_full.yaml
    """
    source = XML.SubElement(xml_parent, 'source', {
        'class': 'jenkins.plugins.git.GitSCMSource',
        'plugin': 'git',
    })
    source_mapping = [
        ('', 'id', '-'.join(['gt', data.get('url', '')])),
        ('url', 'remote', None),
        ('credentials-id', 'credentialsId', ''),
    ]
    helpers.convert_mapping_to_xml(source,
                                   data,
                                   source_mapping,
                                   fail_required=True)

    ##########
    # Traits #
    ##########

    traits_path = 'jenkins.plugins.git.traits'
    traits = XML.SubElement(source, 'traits')

    if data.get('discover-branches', True):
        XML.SubElement(traits, ''.join([traits_path, '.BranchDiscoveryTrait']))

    if data.get('discover-tags', False):
        XML.SubElement(traits, ''.join([traits_path, '.TagDiscoveryTrait']))

    if data.get('ignore-on-push-notifications', False):
        XML.SubElement(
            traits, ''.join([traits_path, '.IgnoreOnPushNotificationTrait']))

    if data.get('head-filter-regex', None):
        rshf = XML.SubElement(
            traits, 'jenkins.scm.impl.trait.RegexSCMHeadFilterTrait')
        XML.SubElement(rshf, 'regex').text = data.get('head-filter-regex')

    if data.get('build-strategies', None):
        build_strategies(xml_parent, data)

    # handle the default git extensions like:
    # - clean
    # - shallow-clone
    # - timeout
    # - do-not-fetch-tags
    # - submodule
    # - prune
    # - wipe-workspace
    # - use-author
    git_extensions(traits, data)
コード例 #6
0
def bitbucket_scm(xml_parent, data):
    r"""Configure BitBucket scm

    Requires the :jenkins-wiki:`Bitbucket Branch Source Plugin
    <Bitbucket+Branch+Source+Plugin>`.

    :arg str credentials-id: The credential to use to scan BitBucket.
        (required)
    :arg str repo-owner: Specify the name of the Bitbucket Team or Bitbucket
        User Account. (required)
    :arg str repo: The BitBucket repo. (required)

    :arg bool discover-tags: Discovers tags on the repository.
        (default false)
    :arg str server-url: The address of the bitbucket server. (optional)
    :arg str head-filter-regex: A regular expression for filtering
        discovered source branches. Requires the :jenkins-wiki:`SCM API Plugin
        <SCM+API+Plugin>`.
    :arg str discovery-branch: Discovers branches on the repository.
        Valid options: ex-pr, only-pr, all.
        Value is not specified by default.
    :arg str discover-pr-origin: Discovers pull requests where the origin
        repository is the same as the target repository.
        Valid options: mergeOnly, headOnly, mergeAndHead.
        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
        (or branch like things such as change requests and tags) whenever it is
        discovered initially or a change from the previous revision has been
        detected. (optional)
        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*`

    :extensions:

        * **clean** (`dict`)
            * **after** (`bool`) - Clean the workspace after checkout
            * **before** (`bool`) - Clean the workspace before checkout
        * **prune** (`bool`) - Prune remote branches (default false)
        * **shallow-clone** (`bool`) - Perform shallow clone (default false)
        * **depth** (`int`) - Set shallow clone depth (default 1)
        * **do-not-fetch-tags** (`bool`) - Perform a clone without tags
            (default false)
        * **submodule** (`dict`)
            * **disable** (`bool`) - By disabling support for submodules you
              can still keep using basic git plugin functionality and just have
              Jenkins to ignore submodules completely as if they didn't exist.
            * **recursive** (`bool`) - Retrieve all submodules recursively
              (uses '--recursive' option which requires git>=1.6.5)
            * **tracking** (`bool`) - Retrieve the tip of the configured
              branch in .gitmodules (Uses '\-\-remote' option which requires
              git>=1.8.2)
            * **parent-credentials** (`bool`) - Use credentials from default
              remote of parent repository (default false).
            * **reference-repo** (`str`) - Path of the reference repo to use
              during clone (optional)
            * **timeout** (`int`) - Specify a timeout (in minutes) for
              submodules operations (default 10).
        * **timeout** (`str`) - Timeout for git commands in minutes (optional)
        * **use-author** (`bool`): Use author rather than committer in Jenkin's
            build changeset (default false)
        * **wipe-workspace** (`bool`) - Wipe out workspace before build
            (default true)


    Minimal Example:

    .. literalinclude::
       /../../tests/multibranch/fixtures/scm_bitbucket_minimal.yaml

    Full Example:

    .. literalinclude::
       /../../tests/multibranch/fixtures/scm_bitbucket_full.yaml
    """
    source = XML.SubElement(
        xml_parent, 'source', {
            'class':
            'com.cloudbees.jenkins.plugins.bitbucket.BitbucketSCMSource',
            'plugin': 'cloudbees-bitbucket-branch-source',
        })
    source_mapping = [
        ('', 'id',
         '-'.join(['bb',
                   data.get('repo-owner', ''),
                   data.get('repo', '')])),
        ('repo-owner', 'repoOwner', None),
        ('repo', 'repository', None),
    ]
    helpers.convert_mapping_to_xml(source,
                                   data,
                                   source_mapping,
                                   fail_required=True)

    mapping_optional = [
        ('credentials-id', 'credentialsId', None),
        ('server-url', 'serverUrl', None),
    ]
    helpers.convert_mapping_to_xml(source,
                                   data,
                                   mapping_optional,
                                   fail_required=False)

    traits = XML.SubElement(source, 'traits')
    if data.get('discover-tags', False):
        XML.SubElement(
            traits,
            'com.cloudbees.jenkins.plugins.bitbucket.TagDiscoveryTrait')
    if data.get('head-filter-regex', None):
        rshf = XML.SubElement(
            traits, 'jenkins.scm.impl.trait.RegexSCMHeadFilterTrait')
        XML.SubElement(rshf, 'regex').text = data.get('head-filter-regex')

    if data.get('discover-pr-origin', None):
        dpro = XML.SubElement(
            traits, 'com.cloudbees.jenkins.plugins.bitbucket'
            '.OriginPullRequestDiscoveryTrait')
        dpro_strategies = {
            'mergeOnly': '1',
            'headOnly': '2',
            'mergeAndHead': '3'
        }
        dpro_mapping = [('discover-pr-origin', 'strategyId', None,
                         dpro_strategies)]
        helpers.convert_mapping_to_xml(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):
        dbr = XML.SubElement(
            traits,
            'com.cloudbees.jenkins.plugins.bitbucket.BranchDiscoveryTrait')
        dbr_strategies = {'ex-pr': '1', 'only-pr': '2', 'all': '3'}
        dbr_mapping = [('discover-branch', 'strategyId', None, dbr_strategies)]
        helpers.convert_mapping_to_xml(dbr,
                                       data,
                                       dbr_mapping,
                                       fail_required=True)

    if data.get('build-strategies', None):
        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)

    # handle the default git extensions like:
    # - clean
    # - shallow-clone
    # - timeout
    # - do-not-fetch-tags
    # - submodule
    # - prune
    # - wipe-workspace
    # - use-author
    git_extensions(traits, data)
コード例 #7
0
def github_org(xml_parent, data):
    r"""Configure GitHub Organization and SCM settings.

    :arg str repo-owner: Specify the name of the GitHub Organization or
        GitHub User Account. (required)
    :arg str api-uri: The GitHub API uri for hosted / on-site GitHub. Must
        first be configured in Global Configuration. (default GitHub)
    :arg str branch-discovery: Discovers branches on the repository.
        Valid options: no-pr, only-pr, all, false. (default 'no-pr')
    :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
        discovered initially or a change from the previous revision has been
        detected. (optional)
        Refer to :func:`~build_strategies <project_multibranch.build_strategies>`.
    :arg str credentials-id: Credentials used to scan branches and pull
        requests, check out sources and mark commit statuses. (optional)
    :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 str discover-pr-origin: Discovers pull requests where the origin
        repository is the same as the target repository.
        Valid options: merge-current, current, both, false.  (default 'merge-current')
    :arg bool discover-tags: Discovers tags on the repository.
        (default false)
    :arg list head-pr-filter-behaviors: Definition of Filter Branch PR behaviors.
        Requires the :jenkins-plugins:`SCM Filter Branch PR Plugin
        <scm-filter-branch-pr>`. Refer to
        :func:`~add_filter_branch_pr_behaviors <project_multibranch.add_filter_branch_pr_behaviors>`.
    :arg str notification-context: Change the default GitHub check notification
        context from "continuous-integration/jenkins/SUFFIX" to a custom text,
        Requires the :jenkins-plugins:`Github Custom Notification Context SCM
        Behaviour <github-scm-trait-notification-context>`.
    :arg dict property-strategies: Provides control over how to build a branch
        (like to disable SCM triggering or to override the pipeline durability)
        (optional)
        Refer to :func:`~property_strategies <project_multibranch.property_strategies>`.
    :arg bool ssh-checkout: Checkout over SSH.

        * **credentials** ('str'): Credentials to use for
            checkout of the repo over ssh.

    :extensions:

        * **clean** (`dict`)
            * **after** (`bool`) - Clean the workspace after checkout
            * **before** (`bool`) - Clean the workspace before checkout
        * **depth** (`int`) - Set shallow clone depth (default 1)
        * **disable-pr-notifications** (`bool`) - Disable default github status
            notifications on pull requests (default false) (Requires the
            :jenkins-plugins:`GitHub Branch Source Plugin
            <disable-github-multibranch-status>`.)
        * **do-not-fetch-tags** (`bool`) - Perform a clone without tags
            (default false)
        * **lfs-pull** (`bool`) - Call git lfs pull after checkout
            (default false)
        * **prune** (`bool`) - Prune remote branches (default false)
        * **refspecs** (`list(str)`): Which refspecs to fetch.
        * **shallow-clone** (`bool`) - Perform shallow clone (default false)
        * **sparse-checkout** (dict)
            * **paths** (list) - List of paths to sparse checkout. (optional)
        * **submodule** (`dict`)
            * **disable** (`bool`) - By disabling support for submodules you
              can still keep using basic git plugin functionality and just have
              Jenkins to ignore submodules completely as if they didn't exist.
            * **recursive** (`bool`) - Retrieve all submodules recursively
              (uses '--recursive' option which requires git>=1.6.5)
            * **tracking** (`bool`) - Retrieve the tip of the configured
              branch in .gitmodules (Uses '\-\-remote' option which requires
              git>=1.8.2)
            * **parent-credentials** (`bool`) - Use credentials from default
              remote of parent repository (default false).
            * **reference-repo** (`str`) - Path of the reference repo to use
              during clone (optional)
            * **timeout** (`int`) - Specify a timeout (in minutes) for
              submodules operations (default 10).
        * **timeout** (`str`) - Timeout for git commands in minutes (optional)
        * **use-author** (`bool`): Use author rather than committer in Jenkin's
            build changeset (default false)
        * **wipe-workspace** (`bool`) - Wipe out workspace before build
            (default true)

    Job examples:

    .. literalinclude:: /../../tests/githuborg/fixtures/minimal.yaml

    .. literalinclude:: /../../tests/githuborg/fixtures/github-org-full.yaml

    """
    github_path = "org.jenkinsci.plugins.github_branch_source"
    github_path_dscore = "org.jenkinsci.plugins.github__branch__source"

    mapping = [("repo-owner", "repoOwner", None)]
    helpers.convert_mapping_to_xml(xml_parent,
                                   data,
                                   mapping,
                                   fail_required=True)

    mapping_optional = [
        ("api-uri", "apiUri", None),
        ("credentials-id", "credentialsId", None),
    ]
    helpers.convert_mapping_to_xml(xml_parent,
                                   data,
                                   mapping_optional,
                                   fail_required=False)

    traits = XML.SubElement(xml_parent, "traits")

    # no-pr value is assumed if branch-discovery not mentioned.
    if data.get("branch-discovery", "no-pr"):
        bd = XML.SubElement(
            traits, "".join([github_path_dscore, ".BranchDiscoveryTrait"]))
        bd_strategy = {"no-pr": "1", "only-pr": "2", "all": "3"}
        bd_mapping = [("branch-discovery", "strategyId", "no-pr", bd_strategy)]
        helpers.convert_mapping_to_xml(bd,
                                       data,
                                       bd_mapping,
                                       fail_required=True)

    if data.get("ssh-checkout", None):
        cossh = XML.SubElement(
            traits, "".join([github_path_dscore, ".SSHCheckoutTrait"]))
        if not isinstance(data.get("ssh-checkout"), bool):
            cossh_credentials = [("credentials", "credentialsId", "")]
            helpers.convert_mapping_to_xml(cossh,
                                           data.get("ssh-checkout"),
                                           cossh_credentials,
                                           fail_required=True)

    if data.get("discover-tags", False):
        XML.SubElement(traits,
                       "".join([github_path_dscore, ".TagDiscoveryTrait"]))

    if data.get("discover-pr-forks-strategy", "merged-current"):
        dprf = XML.SubElement(
            traits,
            "".join([github_path_dscore, ".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([
                github_path, ".ForkPullRequestDiscoveryTrait$TrustContributors"
            ]),
            "everyone":
            "".join(
                [github_path, ".ForkPullRequestDiscoveryTrait$TrustEveryone"]),
            "permission":
            "".join([
                github_path, ".ForkPullRequestDiscoveryTrait$TrustPermission"
            ]),
            "nobody":
            "".join(
                [github_path, ".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]

    dpro_strategy = data.get("discover-pr-origin", "merge-current")
    if dpro_strategy:
        dpro = XML.SubElement(
            traits,
            "".join([github_path_dscore, ".OriginPullRequestDiscoveryTrait"]))
        dpro_strategy_map = {"merge-current": "1", "current": "2", "both": "3"}
        if dpro_strategy not in dpro_strategy_map:
            raise InvalidAttributeError("discover-pr-origin", dpro_strategy,
                                        dpro_strategy_map.keys())
        dpro_mapping = [("discover-pr-origin", "strategyId", "merge-current",
                         dpro_strategy_map)]
        helpers.convert_mapping_to_xml(dpro,
                                       data,
                                       dpro_mapping,
                                       fail_required=True)

    if data.get("head-filter-regex", None):
        rshf = XML.SubElement(
            traits, "jenkins.scm.impl.trait.RegexSCMHeadFilterTrait")
        XML.SubElement(rshf, "regex").text = data.get("head-filter-regex")

    if data.get("head-pr-filter-behaviors", None):
        multibranch.add_filter_branch_pr_behaviors(
            traits, data.get("head-pr-filter-behaviors"))

    if data.get("property-strategies", None):
        multibranch.property_strategies(xml_parent, data)

    if data.get("build-strategies", None):
        multibranch.build_strategies(xml_parent, data)

    if data.get("notification-context", None):
        rshf = XML.SubElement(
            traits,
            "org.jenkinsci.plugins.githubScmTraitNotificationContext."
            "NotificationContextTrait",
        )
        XML.SubElement(rshf,
                       "contextLabel").text = data.get("notification-context")
        XML.SubElement(rshf, "typeSuffix").text = "true"

    # handle the default git extensions like:
    # - clean
    # - shallow-clone
    # - timeout
    # - do-not-fetch-tags
    # - submodule
    # - prune
    # - wipe-workspace
    # - use-author
    # - lfs-pull
    git_extensions(traits, data)

    if data.get("refspecs"):
        refspec_trait = XML.SubElement(
            traits,
            "jenkins.plugins.git.traits.RefSpecsSCMSourceTrait",
            {"plugin": "git"},
        )
        templates = XML.SubElement(refspec_trait, "templates")
        refspecs = data.get("refspecs")
        for refspec in refspecs:
            e = XML.SubElement(
                templates,
                ("jenkins.plugins.git.traits"
                 ".RefSpecsSCMSourceTrait_-RefSpecTemplate"),
            )
            XML.SubElement(e, "value").text = refspec

    # github-only extensions
    disable_github_status_path_dscore = (
        "com.adobe.jenkins.disable__github__multibranch__status")
    if data.get("disable-pr-notifications", False):
        XML.SubElement(
            traits,
            "".join([
                disable_github_status_path_dscore, ".DisableStatusUpdateTrait"
            ]),
            {"plugin": "disable-github-multibranch-status"},
        )