Setting up webhook in a SCM branch source plugin

16 views
Skip to first unread message

Parichay Barpanda

unread,
Jul 26, 2019, 3:32:45 PM7/26/19
to Jenkins Developers
Hi all,

I am working on adding webhook support in GitLab Branch Source Plugin. 

Current implementation looks like this:

1. When `afterSave()` method is called upon in `GitLabSCMSource` or `GitLabSCMNavigator` then a webhook url is created in the GitLab Server by `GitLabWebhookCreator` class. Creation of webhook depend on the mode chosen by user.

2. When an event occurs in GitLab Server, `GitLabWebhookAction` class which implements an `UnprotectedRootAction` processes the http request.

3. The request is then sent to `GitLabWebhookManager` class which is provided with a listener called `GitLabWebhookListener` which listens to the GitLabEvent.

4. `GitLabWebhookListener` provides the onEvent methods like `onMergeRequest`, `onPushEvent` etc. The `GitLabWebhookListener` works correctly and each method gets their respective GitLab event. (as is logged)

5. With the help of GitLab specific event object(`PushEvent`, `MergeRequestEvent` etc) now I am creating a Jenkins specific SCMHeadEvent e.g. `GitLabPushSCMEvent`, `GitLabMergeRequestSCMEvent` etc. 

6. Now when I fire any of these event e.g. `SCMHeadEvent.fireNow(GitLabPushSCMEvent)`, it doesn't fire the event.

I know all this is confusing, looking at the codebase can help? https://github.com/jenkinsci/gitlab-branch-source-plugin/.

I want to know how does an `SCMSource` or `SCMNavigator` listen to a SCMHeadEvent? I think in all the above implementation I have missed the part of setting a listener on source and navigator itself as they don't receive any project events. At the same time I am unable to figure out how to setup a listener on them. Can someone help me with this? Some toplevel idea of how SCMHeadEvent works will also be a big help for me.

Thanks in advance.

Jesse Glick

unread,
Jul 26, 2019, 3:52:18 PM7/26/19
to Jenkins Dev
On Fri, Jul 26, 2019 at 3:32 PM Parichay Barpanda
<parichay...@gmail.com> wrote:
> Some toplevel idea of how SCMHeadEvent works will also be a big help for me.

https://github.com/jenkinsci/scm-api-plugin/blob/master/docs/implementation.adoc#implementing-event-support

Parichay Barpanda

unread,
Jul 26, 2019, 4:43:03 PM7/26/19
to jenkin...@googlegroups.com
Thanks for the pointer. I have done same mapping of the event payload to SCM API Event. Also created a RootAction for the webhook. 

Can you tell me what happens when SCMHeadEvent.fireNow(event) is called upon? My understanding is that it takes the SCM API mapped event then iterates through all the SCMEventListeners and based on `isMatch` method it triggers the event. In my case either my GitLabSCMSource doesn't have an SCMEventListener or isMatch method returns false for the required source. If it is the latter case then my mapping maybe incorrect?

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-de...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/CANfRfr1EqmtqF09BQO569WvoU2-c1X-nh%3DbgOCstzg%3DEZjw7mA%40mail.gmail.com.

Jesse Glick

unread,
Jul 29, 2019, 11:15:53 AM7/29/19
to Jenkins Dev
On Fri, Jul 26, 2019 at 4:43 PM Parichay Barpanda
<parichay...@gmail.com> wrote:
> Can you tell me what happens when SCMHeadEvent.fireNow(event) is called upon? My understanding is that it takes the SCM API mapped event then iterates through all the SCMEventListeners and based on `isMatch` method it triggers the event. In my case either my GitLabSCMSource doesn't have an SCMEventListener or isMatch method returns false for the required source. If it is the latter case then my mapping maybe incorrect?

I am afraid you are beyond what I can answer. Maybe someone who works
more deeply in this area can help?
Reply all
Reply to author
Forward
0 new messages