Merge "Add support for stash-pullrequest-builder plugin"

This commit is contained in:
Zuul 2017-12-27 16:22:53 +00:00 committed by Gerrit Code Review
commit 685aba502a
5 changed files with 144 additions and 0 deletions

View File

@ -1924,6 +1924,77 @@ def jira_comment_trigger(registry, xml_parent, data):
parent, parameter, parameter_mappings, fail_required=True)
def stash_pull_request(registry, xml_parent, data):
"""yaml: stash-pull-request
Trigger builds via Stash/Bitbucket Server Pull Requests.
Requires the Jenkins :jenkins-wiki:`Stash Pull Request Builder Plugin
<Stash+pullrequest+builder+plugin>`.
:arg str cron: cron syntax of when to run (required)
:arg str stash-host: The HTTP or HTTPS URL of the Stash host (NOT ssh).
e.g.: https://example.com (required)
:arg str credentials-id: Jenkins credential set to use. (required)
:arg str project: Abbreviated project code. e.g.: PRJ or ~user (required)
:arg str repository: Stash Repository Name. e.g.: Repo (required)
:arg str ci-skip-phrases: CI Skip Phrases. (default 'NO TEST')
:arg str ci-build-phrases: CI Build Phrases. (default 'test this please')
:arg str target-branches: Target branches to filter. (default '')
:arg bool ignore-ssl: Ignore SSL certificates for Stash host.
(default false)
:arg bool check-destination-commit: Rebuild if destination branch
changes. (default false)
:arg bool check-mergable: Build only if PR is mergeable. (default false)
:arg bool merge-on-success: Merge PR if build is successful.
(default false)
:arg bool check-not-conflicted: Build only if Stash reports no conflicts.
(default false)
:arg bool only-build-on-comment: Only build when asked (with test
phrase). (default false)
:arg bool delete-previous-build-finish-comments: Keep PR comment only for
most recent Build. (default false)
:arg bool cancel-outdated-jobs: Cancel outdated jobs. (default false)
Minimal Example:
.. literalinclude::
/../../tests/triggers/fixtures/stash-pull-request-minimal.yaml
:language: yaml
Full Example:
.. literalinclude::
/../../tests/triggers/fixtures/stash-pull-request-full.yaml
:language: yaml
"""
pr_trigger = XML.SubElement(
xml_parent,
'stashpullrequestbuilder.stashpullrequestbuilder.StashBuildTrigger')
pr_trigger.set('plugin', 'stash-pullrequest-builder')
mappings = [
('cron', 'spec', None), # Spec needs to be set to the same as cron
('cron', 'cron', None),
('stash-host', 'stashHost', None),
('credentials-id', 'credentialsId', None),
('project', 'projectCode', None),
('repository', 'repositoryName', None),
('ci-skip-phrases', 'ciSkipPhrases', 'NO TEST'),
('ci-build-phrases', 'ciBuildPhrases', 'test this please'),
('target-branches', 'targetBranchesToBuild', ''),
('ignore-ssl', 'ignoreSsl', False),
('check-destination-commit', 'checkDestinationCommit', False),
('check-mergable', 'checkMergeable', False),
('merge-on-success', 'mergeOnSuccess', False),
('check-not-conflicted', 'checkNotConflicted', True),
('only-build-on-comment', 'onlyBuildOnComment', False),
('delete-previous-build-finish-comments',
'deletePreviousBuildFinishComments', False),
('cancel-outdated-jobs', 'cancelOutdatedJobsEnabled', False),
]
convert_mapping_to_xml(pr_trigger, data, mappings, fail_required=True)
class Triggers(jenkins_jobs.modules.base.Base):
sequence = 50

View File

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<project>
<triggers class="vector">
<stashpullrequestbuilder.stashpullrequestbuilder.StashBuildTrigger plugin="stash-pullrequest-builder">
<spec>H 1 2 3 4</spec>
<cron>H 1 2 3 4</cron>
<stashHost>https://stash-host.com</stashHost>
<credentialsId>default-stash-credentials</credentialsId>
<projectCode>stash-project</projectCode>
<repositoryName>stash-repo</repositoryName>
<ciSkipPhrases>test skip phrase</ciSkipPhrases>
<ciBuildPhrases>test build phrase</ciBuildPhrases>
<targetBranchesToBuild>master</targetBranchesToBuild>
<ignoreSsl>true</ignoreSsl>
<checkDestinationCommit>true</checkDestinationCommit>
<checkMergeable>true</checkMergeable>
<mergeOnSuccess>true</mergeOnSuccess>
<checkNotConflicted>false</checkNotConflicted>
<onlyBuildOnComment>true</onlyBuildOnComment>
<deletePreviousBuildFinishComments>true</deletePreviousBuildFinishComments>
<cancelOutdatedJobsEnabled>true</cancelOutdatedJobsEnabled>
</stashpullrequestbuilder.stashpullrequestbuilder.StashBuildTrigger>
</triggers>
</project>

View File

@ -0,0 +1,18 @@
triggers:
- stash-pull-request:
cron: "H 1 2 3 4"
stash-host: "https://stash-host.com"
credentials-id: default-stash-credentials
project: stash-project
repository: stash-repo
ci-skip-phrases: "test skip phrase"
ci-build-phrases: "test build phrase"
target-branches: "master"
ignore-ssl: true
check-destination-commit: true
check-mergable: true
merge-on-success: true
check-not-conflicted: false
only-build-on-comment: true
delete-previous-build-finish-comments: true
cancel-outdated-jobs: true

View File

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<project>
<triggers class="vector">
<stashpullrequestbuilder.stashpullrequestbuilder.StashBuildTrigger plugin="stash-pullrequest-builder">
<spec>* * * * *</spec>
<cron>* * * * *</cron>
<stashHost>https://stash-host.com</stashHost>
<credentialsId>default-stash-credentials</credentialsId>
<projectCode>stash-project</projectCode>
<repositoryName>stash-repo</repositoryName>
<ciSkipPhrases>NO TEST</ciSkipPhrases>
<ciBuildPhrases>test this please</ciBuildPhrases>
<targetBranchesToBuild/>
<ignoreSsl>false</ignoreSsl>
<checkDestinationCommit>false</checkDestinationCommit>
<checkMergeable>false</checkMergeable>
<mergeOnSuccess>false</mergeOnSuccess>
<checkNotConflicted>true</checkNotConflicted>
<onlyBuildOnComment>false</onlyBuildOnComment>
<deletePreviousBuildFinishComments>false</deletePreviousBuildFinishComments>
<cancelOutdatedJobsEnabled>false</cancelOutdatedJobsEnabled>
</stashpullrequestbuilder.stashpullrequestbuilder.StashBuildTrigger>
</triggers>
</project>

View File

@ -0,0 +1,7 @@
triggers:
- stash-pull-request:
cron: "* * * * *"
stash-host: "https://stash-host.com"
credentials-id: default-stash-credentials
project: stash-project
repository: stash-repo