Add properties for Gitlab trigger

Add source branch regex property for gitlab trigger
Add merge request label filtering options to gitlab trigger

Change-Id: Idbcec2952459b80b8b35133a1c4913ec195b5ff7
This commit is contained in:
Mateusz Rygiel 2022-12-30 16:04:43 +01:00
parent 0e1b708ad5
commit 456e64513f
12 changed files with 72 additions and 1 deletions

View File

@ -1671,8 +1671,14 @@ def gitlab(registry, xml_parent, data):
(default [])
:arg list exclude-branches: Defined list of branches to exclude
(default [])
:arg str source-branch-regex: Regular expression to select branches
:arg str target-branch-regex: Regular expression to select branches
:arg str secret-token: Secret token for build trigger
:arg dict merge-request-label-filter-config: If used allow merge requests
filtering by labels
:Options: * **include** (`str`) Run for specified labels.
* **exclude** (`str`) Do not run for specified labels.
.. _`branch filter type`:
@ -1692,7 +1698,7 @@ def gitlab(registry, xml_parent, data):
The target branch regex allows you to limit the
execution of this job to certain branches. Any
branch matching the specified pattern in
**target-branch-regex** triggers the job. No
**target-branch-regex** and **source-branch-regex** triggers the job. No
filtering is performed if the field is left empty.
================== ====================================================
@ -1772,6 +1778,7 @@ def gitlab(registry, xml_parent, data):
("accept-merge-request-on-success", "acceptMergeRequestOnSuccess", False),
("add-ci-message", "addCiMessage", False),
("allow-all-branches", "allowAllBranches", False),
("source-branch-regex", "sourceBranchRegex", ""),
("target-branch-regex", "targetBranchRegex", ""),
("secret-token", "secretToken", ""),
]
@ -1788,6 +1795,19 @@ def gitlab(registry, xml_parent, data):
optional_mapping = (("pending-build-name", "pendingBuildName", None),)
helpers.convert_mapping_to_xml(gitlab, data, optional_mapping, fail_required=False)
if data.get("merge-request-label-filter-config"):
merge_request_filter = XML.SubElement(gitlab, "mergeRequestLabelFilterConfig")
merge_mapping = [
("include", "include", ""),
("exclude", "exclude", ""),
]
helpers.convert_mapping_to_xml(
merge_request_filter,
data.get("merge-request-label-filter-config", ""),
merge_mapping,
fail_required=False,
)
def gogs(registry, xml_parent, data):
"""yaml: gogs

View File

@ -21,6 +21,7 @@
<acceptMergeRequestOnSuccess>false</acceptMergeRequestOnSuccess>
<addCiMessage>true</addCiMessage>
<allowAllBranches>true</allowAllBranches>
<sourceBranchRegex/>
<targetBranchRegex/>
<secretToken/>
<includeBranchesSpec>master, master2, local-test</includeBranchesSpec>

View File

@ -21,6 +21,7 @@
<acceptMergeRequestOnSuccess>false</acceptMergeRequestOnSuccess>
<addCiMessage>false</addCiMessage>
<allowAllBranches>false</allowAllBranches>
<sourceBranchRegex/>
<targetBranchRegex/>
<secretToken/>
<includeBranchesSpec>master</includeBranchesSpec>

View File

@ -21,6 +21,7 @@
<acceptMergeRequestOnSuccess>false</acceptMergeRequestOnSuccess>
<addCiMessage>false</addCiMessage>
<allowAllBranches>false</allowAllBranches>
<sourceBranchRegex/>
<targetBranchRegex/>
<secretToken/>
<includeBranchesSpec>master</includeBranchesSpec>

View File

@ -21,6 +21,7 @@
<acceptMergeRequestOnSuccess>false</acceptMergeRequestOnSuccess>
<addCiMessage>true</addCiMessage>
<allowAllBranches>true</allowAllBranches>
<sourceBranchRegex/>
<targetBranchRegex/>
<secretToken/>
<includeBranchesSpec>master, master2, local-test</includeBranchesSpec>

View File

@ -21,6 +21,7 @@
<acceptMergeRequestOnSuccess>false</acceptMergeRequestOnSuccess>
<addCiMessage>false</addCiMessage>
<allowAllBranches>false</allowAllBranches>
<sourceBranchRegex/>
<targetBranchRegex/>
<secretToken/>
<includeBranchesSpec/>

View File

@ -21,6 +21,7 @@
<acceptMergeRequestOnSuccess>true</acceptMergeRequestOnSuccess>
<addCiMessage>true</addCiMessage>
<allowAllBranches>false</allowAllBranches>
<sourceBranchRegex/>
<targetBranchRegex>(.*debug.*|.*release.*)</targetBranchRegex>
<secretToken>secret-build-token</secretToken>
<includeBranchesSpec>include1, include2</includeBranchesSpec>

View File

@ -21,6 +21,7 @@
<acceptMergeRequestOnSuccess>false</acceptMergeRequestOnSuccess>
<addCiMessage>true</addCiMessage>
<allowAllBranches>true</allowAllBranches>
<sourceBranchRegex/>
<targetBranchRegex/>
<secretToken/>
<includeBranchesSpec>master, master2, local-test</includeBranchesSpec>

View File

@ -21,6 +21,7 @@
<acceptMergeRequestOnSuccess>false</acceptMergeRequestOnSuccess>
<addCiMessage>true</addCiMessage>
<allowAllBranches>false</allowAllBranches>
<sourceBranchRegex/>
<targetBranchRegex/>
<secretToken/>
<includeBranchesSpec/>

View File

@ -0,0 +1,3 @@
- longName: 'GitLab Plugin'
shortName: 'gitlab-plugin'
version: "0"

View File

@ -0,0 +1,35 @@
<?xml version="1.0" encoding="utf-8"?>
<project>
<triggers class="vector">
<com.dabsquared.gitlabjenkins.GitLabPushTrigger>
<triggerOpenMergeRequestOnPush>true</triggerOpenMergeRequestOnPush>
<branchFilterName/>
<spec/>
<triggerOnPush>true</triggerOnPush>
<triggerOnMergeRequest>true</triggerOnMergeRequest>
<triggerOnlyIfNewCommitsPushed>false</triggerOnlyIfNewCommitsPushed>
<triggerOnAcceptedMergeRequest>false</triggerOnAcceptedMergeRequest>
<triggerOnClosedMergeRequest>false</triggerOnClosedMergeRequest>
<triggerOnNoteRequest>true</triggerOnNoteRequest>
<noteRegex>Jenkins please retry a build</noteRegex>
<ciSkip>true</ciSkip>
<skipWorkInProgressMergeRequest>true</skipWorkInProgressMergeRequest>
<setBuildDescription>true</setBuildDescription>
<cancelPendingBuildsOnUpdate>false</cancelPendingBuildsOnUpdate>
<addNoteOnMergeRequest>true</addNoteOnMergeRequest>
<addVoteOnMergeRequest>true</addVoteOnMergeRequest>
<acceptMergeRequestOnSuccess>false</acceptMergeRequestOnSuccess>
<addCiMessage>false</addCiMessage>
<allowAllBranches>false</allowAllBranches>
<sourceBranchRegex/>
<targetBranchRegex/>
<secretToken/>
<includeBranchesSpec/>
<excludeBranchesSpec/>
<mergeRequestLabelFilterConfig>
<include>IncludedLabel</include>
<exclude>ExcludedLabel</exclude>
</mergeRequestLabelFilterConfig>
</com.dabsquared.gitlabjenkins.GitLabPushTrigger>
</triggers>
</project>

View File

@ -0,0 +1,5 @@
triggers:
- gitlab:
merge-request-label-filter-config:
include: "IncludedLabel"
exclude: "ExcludedLabel"