From fd1956e3a07ab2e5b63316f17b8897c1992d6e62 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Mar 12 2019 08:45:05 +0000 Subject: [PATCH 1/2] Include the target branch of the PR when triggering jenkins In addition to the repo and branch from which the PR originates from and either the commit hash or the PR id, include the target branch of the PR Fixes https://pagure.io/pagure/issue/4317 Signed-off-by: Pierre-Yves Chibon --- diff --git a/pagure/hooks/default.py b/pagure/hooks/default.py index 475969a..cc62020 100644 --- a/pagure/hooks/default.py +++ b/pagure/hooks/default.py @@ -172,6 +172,7 @@ def send_notifications(session, project, repodir, user, refname, revs, forced): cause=revs[-1], branch=refname, ci_type=project.ci_hook.ci_type, + branch_to=None, ) diff --git a/pagure/lib/lib_ci.py b/pagure/lib/lib_ci.py index bc3693d..f2a30ec 100644 --- a/pagure/lib/lib_ci.py +++ b/pagure/lib/lib_ci.py @@ -129,7 +129,9 @@ def process_jenkins_build(session, project, build_id, iteration=0): session.commit() -def trigger_jenkins_build(project_path, url, job, token, branch, cause): +def trigger_jenkins_build( + project_path, url, job, token, branch, branch_to, cause +): """ Trigger a build on a jenkins instance.""" try: import jenkins @@ -141,7 +143,12 @@ def trigger_jenkins_build(project_path, url, job, token, branch, cause): repo = "%s/%s" % (pagure_config["GIT_URL_GIT"].rstrip("/"), project_path) - data = {"cause": cause, "REPO": repo, "BRANCH": branch} + data = { + "cause": cause, + "REPO": repo, + "BRANCH": branch, + "BRANCH_TO": branch_to, + } server = jenkins.Jenkins(url) _log.info( diff --git a/pagure/lib/query.py b/pagure/lib/query.py index a9257f2..5313c9e 100644 --- a/pagure/lib/query.py +++ b/pagure/lib/query.py @@ -1347,6 +1347,7 @@ def add_pull_request_comment( pr_uid=request.uid, cause=request.id, branch=request.branch_from, + branch_to=request.branch, ci_type=request.project.ci_hook.ci_type, ) ci_triggered = True @@ -1371,6 +1372,7 @@ def add_pull_request_comment( pr_uid=request.uid, cause=request.id, branch=request.branch_from, + branch_to=request.branch, ci_type=request.project.ci_hook.ci_type, ) @@ -1909,6 +1911,7 @@ def new_pull_request( pr_uid=request.uid, cause=request.id, branch=request.branch_from, + branch_to=request.branch, ci_type=request.project.ci_hook.ci_type, ) diff --git a/pagure/lib/tasks_services.py b/pagure/lib/tasks_services.py index 6a30446..4cef4e9 100644 --- a/pagure/lib/tasks_services.py +++ b/pagure/lib/tasks_services.py @@ -392,7 +392,14 @@ def load_json_commits_to_db( @conn.task(queue=pagure_config.get("CI_CELERY_QUEUE", None), bind=True) @pagure_task def trigger_ci_build( - self, session, cause, branch, ci_type, project_name=None, pr_uid=None + self, + session, + cause, + branch, + branch_to, + ci_type, + project_name=None, + pr_uid=None, ): """ Triggers a new run of the CI system on the specified pull-request. @@ -471,6 +478,7 @@ def trigger_ci_build( job=job, token=token, branch=branch, + branch_to=branch_to, cause=cause, ) diff --git a/tests/test_pagure_lib_task_services.py b/tests/test_pagure_lib_task_services.py index 6c2b2e4..a5063bd 100644 --- a/tests/test_pagure_lib_task_services.py +++ b/tests/test_pagure_lib_task_services.py @@ -122,6 +122,7 @@ class PagureLibTaskServicestests(tests.Modeltests): project_name='invalid', cause='PR#ID', branch='feature', + branch_to='master', ci_type='jenkins') self.assertIsNone(output) trigger_jenk.assert_not_called() @@ -135,6 +136,7 @@ class PagureLibTaskServicestests(tests.Modeltests): project_name='test', cause='PR#ID', branch='feature', + branch_to='master', ci_type='jenkins') trigger_jenk.assert_not_called() @@ -147,6 +149,7 @@ class PagureLibTaskServicestests(tests.Modeltests): project_name='forks/foo/test', cause='PR#ID', branch='feature', + branch_to='master', ci_type='jenkins') trigger_jenk.assert_not_called() @@ -554,6 +557,7 @@ class PagureLibTaskServicesJenkinsCItests(tests.Modeltests): project_name='test', cause='PR#ID', branch='feature', + branch_to='master', ci_type='travis') self.assertIsNone(output) trigger_jenk.assert_not_called() @@ -565,6 +569,7 @@ class PagureLibTaskServicesJenkinsCItests(tests.Modeltests): project_name='forks/foo/test', cause='PR#ID', branch='feature', + branch_to='master', ci_type='travis') self.assertIsNone(output) trigger_jenk.assert_not_called() @@ -576,6 +581,7 @@ class PagureLibTaskServicesJenkinsCItests(tests.Modeltests): project_name='test', cause='PR#ID', branch='feature', + branch_to='master', ci_type='jenkins') self.assertIsNone(output) trigger_jenk.assert_called_once_with( @@ -584,7 +590,8 @@ class PagureLibTaskServicesJenkinsCItests(tests.Modeltests): job=u'pagure', project_path=u'test.git', token=u'random_token', - url=u'https://ci.server.org/' + url=u'https://ci.server.org/', + branch_to='master', ) @patch('pagure.lib.tasks_services.trigger_jenkins_build') @@ -594,6 +601,7 @@ class PagureLibTaskServicesJenkinsCItests(tests.Modeltests): project_name='forks/foo/test', cause='PR#ID', branch='feature', + branch_to='master', ci_type='jenkins') self.assertIsNone(output) trigger_jenk.assert_called_once_with( @@ -602,7 +610,8 @@ class PagureLibTaskServicesJenkinsCItests(tests.Modeltests): job=u'pagure', project_path=u'forks/foo/test.git', token=u'random_token', - url=u'https://ci.server.org/' + url=u'https://ci.server.org/', + branch_to='master', ) From 71a995b7ce93fa2c7b683f0bc25a39e7565a2629 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Mar 12 2019 08:45:05 +0000 Subject: [PATCH 2/2] Add some documentation on how pagure-ci works and which info are sent to jenkins Signed-off-by: Pierre-Yves Chibon --- diff --git a/doc/usage/pagure_ci_jenkins.rst b/doc/usage/pagure_ci_jenkins.rst index 0a3302b..69ff435 100644 --- a/doc/usage/pagure_ci_jenkins.rst +++ b/doc/usage/pagure_ci_jenkins.rst @@ -6,6 +6,35 @@ integrated with pagure. This document describe the steps needed to make it work. +How does it work? +----------------- + +The principal is: +* pagure will trigger a build on jenkins when a pull-request is created, + updated or when someone explicitely asks pagure to do so or when a new commit + is pushed (if pagure-ci is configured to trigger on commit). + +* pagure will send a few information to jenkins when triggering a build: + ``REPO``, ``BRANCH``, ``BRANCH_TO``, ``cause``. + +* jenkins will do its work and, using webhook, report to pagure that it has + finished its task + +* pagure will query jenkins to know the outcome of the task and flag the PR + accordingly + +``REPO`` corresponds to the url of the repository the pull-request originates +from (so most often it will be a fork of the main repository). + +``BRANCH`` corresponds to the branch the pull-request originates from (the +branch of the fork). + +``BRANCH_TO`` corresponds to the targeted branch in the main repository (the +branch of the main project in which the PR is to be merged). + +``cause`` is the reason the build was triggered (ie: the pull-request id or the +commit hash). + How to enable Pagure CI -----------------------