summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSergey Rotaru <badwings@yandex.ru>2020-06-07 14:23:33 +0300
committerRotaru Sergey <badwings@yandex.ru>2020-06-14 17:19:05 +0300
commit67c2decc3afc5ce97537ee8ed21528969ded058d (patch)
tree176f4883bc5f1ba1a5cdefb635713bb46a8dfa16
parent6c55bc78212536a9fe59f35b4c199ebe2c305844 (diff)
downloadpython-jenkins-job-builder-67c2decc3afc5ce97537ee8ed21528969ded058d.tar.gz
python-jenkins-job-builder-67c2decc3afc5ce97537ee8ed21528969ded058d.tar.xz
python-jenkins-job-builder-67c2decc3afc5ce97537ee8ed21528969ded058d.zip
Implement GitHub PR Comment Build Plugin
Added support of trigger-build-on-pr-comment, trigger-build-on-pr-rewiev, trigger-build-on-pr-update options for multibranch project. Modified multibranch test case to cover new options. Change-Id: Ia8658b49e7f7806ef1a8f34de10eaee5b3b7b488 Signed-off-by: Rotaru Sergey <badwings@yandex.ru>
-rw-r--r--jenkins_jobs/modules/project_multibranch.py67
-rw-r--r--tests/multibranch/fixtures/scm_github_full.xml5
-rw-r--r--tests/multibranch/fixtures/scm_github_full.yaml3
3 files changed, 74 insertions, 1 deletions
diff --git a/jenkins_jobs/modules/project_multibranch.py b/jenkins_jobs/modules/project_multibranch.py
index 93b5f380..f76263e3 100644
--- a/jenkins_jobs/modules/project_multibranch.py
+++ b/jenkins_jobs/modules/project_multibranch.py
@@ -1193,7 +1193,27 @@ def property_strategies(xml_parent, data):
max-survivability (optional)
Requires the :jenkins-plugins:`Pipeline Multibranch Plugin
<workflow-multibranch>`
-
+ * **trigger-build-on-pr-comment** (str): The comment body to
+ trigger a new build for a PR job when it is received. This
+ is compiled as a case insensitive regular expression, so
+ use ``".*"`` to trigger a build on any comment whatsoever.
+ (optional)
+ Requires the :jenkins-plugins:`GitHub PR Comment Build Plugin
+ <github-pr-comment-build>`
+ * **trigger-build-on-pr-review** (bool): This property will
+ cause a job for a pull request ``(PR-*)`` to be triggered
+ immediately when a review is made on the PR in GitHub.
+ This has no effect on jobs that are not for pull requests.
+ (optional)
+ Requires the :jenkins-plugins:`GitHub PR Comment Build Plugin
+ <github-pr-comment-build>`
+ * **trigger-build-on-pr-update** (bool): This property will
+ cause a job for a pull request ``(PR-*)`` to be triggered
+ immediately when the PR title or description is edited in
+ GitHub. This has no effect on jobs that are not for pull
+ requests. (optional)
+ Requires the :jenkins-plugins:`GitHub PR Comment Build Plugin
+ <github-pr-comment-build>`
* **named-branches** (dict): Named branches get different properties.
Comprised of a list of defaults and a list of property strategy
exceptions for use with specific branches.
@@ -1210,6 +1230,27 @@ def property_strategies(xml_parent, data):
max-survivability (optional)
Requires the :jenkins-plugins:`Pipeline Multibranch Plugin
<workflow-multibranch>`
+ * **trigger-build-on-pr-comment** (str): The comment body to
+ trigger a new build for a PR job when it is received. This
+ is compiled as a case insensitive regular expression, so
+ use ``".*"`` to trigger a build on any comment whatsoever.
+ (optional)
+ Requires the :jenkins-plugins:`GitHub PR Comment Build Plugin
+ <github-pr-comment-build>`
+ * **trigger-build-on-pr-review** (bool): This property will
+ cause a job for a pull request ``(PR-*)`` to be triggered
+ immediately when a review is made on the PR in GitHub.
+ This has no effect on jobs that are not for pull requests.
+ (optional)
+ Requires the :jenkins-plugins:`GitHub PR Comment Build Plugin
+ <github-pr-comment-build>`
+ * **trigger-build-on-pr-update** (bool): This property will
+ cause a job for a pull request ``(PR-*)`` to be triggered
+ immediately when the PR title or description is edited in
+ GitHub. This has no effect on jobs that are not for pull
+ requests. (optional)
+ Requires the :jenkins-plugins:`GitHub PR Comment Build Plugin
+ <github-pr-comment-build>`
* **exceptions** (list): A list of branch names and the property
strategies to be used on that branch, instead of any listed
@@ -1375,6 +1416,7 @@ def apply_property_strategies(props_elem, props_list):
basic_property_strategies = "jenkins.branch"
workflow_multibranch = "org.jenkinsci.plugins.workflow.multibranch"
+ pr_comment_build = "com.adobe.jenkins.github__pr__comment__build"
# Valid options for the pipeline branch durability override.
pbdo_map = collections.OrderedDict(
[
@@ -1384,6 +1426,13 @@ def apply_property_strategies(props_elem, props_list):
]
)
+ pcb_bool_opts = collections.OrderedDict(
+ [
+ ("trigger-build-on-pr-review", ".TriggerPRReviewBranchProperty"),
+ ("trigger-build-on-pr-update", ".TriggerPRUpdateBranchProperty"),
+ ]
+ )
+
for dbs_list in props_list:
if dbs_list.get("suppress-scm-triggering", False):
@@ -1404,3 +1453,19 @@ def apply_property_strategies(props_elem, props_list):
{"plugin": "workflow-multibranch"},
)
XML.SubElement(pbdo_elem, "hint").text = pbdo_map.get(pbdo_val)
+
+ tbopc_val = dbs_list.get("trigger-build-on-pr-comment", None)
+ if tbopc_val:
+ tbopc_elem = XML.SubElement(
+ props_elem,
+ "".join([pr_comment_build, ".TriggerPRCommentBranchProperty"]),
+ {"plugin": "github-pr-comment-build"},
+ )
+ XML.SubElement(tbopc_elem, "commentBody").text = tbopc_val
+ for opt in pcb_bool_opts:
+ if dbs_list.get(opt, False):
+ XML.SubElement(
+ props_elem,
+ "".join([pr_comment_build, pcb_bool_opts.get(opt)]),
+ {"plugin": "github-pr-comment-build"},
+ )
diff --git a/tests/multibranch/fixtures/scm_github_full.xml b/tests/multibranch/fixtures/scm_github_full.xml
index 2d914b2b..6a52b72a 100644
--- a/tests/multibranch/fixtures/scm_github_full.xml
+++ b/tests/multibranch/fixtures/scm_github_full.xml
@@ -107,6 +107,11 @@
<org.jenkinsci.plugins.workflow.multibranch.DurabilityHintBranchProperty plugin="workflow-multibranch">
<hint>MAX_SURVIVABILITY</hint>
</org.jenkinsci.plugins.workflow.multibranch.DurabilityHintBranchProperty>
+ <com.adobe.jenkins.github__pr__comment__build.TriggerPRCommentBranchProperty plugin="github-pr-comment-build">
+ <commentBody>Ci build!</commentBody>
+ </com.adobe.jenkins.github__pr__comment__build.TriggerPRCommentBranchProperty>
+ <com.adobe.jenkins.github__pr__comment__build.TriggerPRReviewBranchProperty plugin="github-pr-comment-build"/>
+ <com.adobe.jenkins.github__pr__comment__build.TriggerPRUpdateBranchProperty plugin="github-pr-comment-build"/>
</a>
</properties>
</strategy>
diff --git a/tests/multibranch/fixtures/scm_github_full.yaml b/tests/multibranch/fixtures/scm_github_full.yaml
index 42350c67..591e0fd8 100644
--- a/tests/multibranch/fixtures/scm_github_full.yaml
+++ b/tests/multibranch/fixtures/scm_github_full.yaml
@@ -20,6 +20,9 @@ scm:
all-branches:
- suppress-scm-triggering: true
- pipeline-branch-durability-override: max-survivability
+ - trigger-build-on-pr-comment: "Ci build!"
+ - trigger-build-on-pr-review: true
+ - trigger-build-on-pr-update: true
build-strategies:
- tags:
ignore-tags-newer-than: 1