#4347 Include the target branch of the PR when triggering jenkins
Merged 5 years ago by pingou. Opened 5 years ago by pingou.

@@ -6,6 +6,35 @@ 

  

  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

  -----------------------

file modified
+1
@@ -172,6 +172,7 @@ 

                  cause=revs[-1],

                  branch=refname,

                  ci_type=project.ci_hook.ci_type,

+                 branch_to=None,

              )

  

  

file modified
+9 -2
@@ -129,7 +129,9 @@ 

      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 @@ 

  

      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(

file modified
+3
@@ -1347,6 +1347,7 @@ 

              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 @@ 

              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 @@ 

              pr_uid=request.uid,

              cause=request.id,

              branch=request.branch_from,

+             branch_to=request.branch,

              ci_type=request.project.ci_hook.ci_type,

          )

  

file modified
+9 -1
@@ -392,7 +392,14 @@ 

  @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 @@ 

              job=job,

              token=token,

              branch=branch,

+             branch_to=branch_to,

              cause=cause,

          )

  

@@ -122,6 +122,7 @@ 

              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 @@ 

              project_name='test',

              cause='PR#ID',

              branch='feature',

+             branch_to='master',

              ci_type='jenkins')

          trigger_jenk.assert_not_called()

  
@@ -147,6 +149,7 @@ 

              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 @@ 

              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 @@ 

              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 @@ 

              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 @@ 

             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 @@ 

              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 @@ 

             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',

          )