Facing issue in configuring hooks

171 views
Skip to first unread message

Lokesh Loki

unread,
Sep 15, 2023, 7:53:31 AM9/15/23
to Repo and Gerrit Discussion
Hi All,

I tried configuring hooks in gerrit.config file as below 

[hooks]
        patchset-created = /home/gerrit/gerritsite/hooks/patchset-created
        ref-updated = /home/gerrit/gerritsite/hooks/ref-updated
        change-merged = /home/gerrit/gerritsite/hooks/change-merged

respective files are kept in hooks/ directory.But when a change is pushed or patchset is added etc., hooks is not getting triggered.

I have also tried changing names like patchsetCreated , refUpdated, changeMerged inplace of above values but it didnt worked. Request you to Kindly assist me in resolving this issue.

If it is possible to trigger hook with arguments (like capability of sending project name, commit info etc., to hook script) , please share the configuration for that

Thanks and Regards,
Lokesh M

Sven Selberg

unread,
Sep 15, 2023, 8:14:56 AM9/15/23
to Repo and Gerrit Discussion
On Friday, September 15, 2023 at 1:53:31 PM UTC+2 Lokesh Loki wrote:
Hi All,

I tried configuring hooks in gerrit.config file as below 

[hooks]
        patchset-created = /home/gerrit/gerritsite/hooks/patchset-created
        ref-updated = /home/gerrit/gerritsite/hooks/ref-updated
        change-merged = /home/gerrit/gerritsite/hooks/change-merged

respective files are kept in hooks/ directory.But when a change is pushed or patchset is added etc., hooks is not getting triggered.

Lokesh Loki

unread,
Sep 15, 2023, 11:58:13 AM9/15/23
to Repo and Gerrit Discussion
I am using 3.8.1 version.
Hooks plugin is already installed.
Hooks are executable.
I dont see any error for ref updated and patchset created in the logs. Below are logs :

[2023-09-15T15:48:21.756Z] [ReceiveCommits-1[java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask@20b09beb[Not completed, task = java.util.concurrent.Executors$RunnableAdapter@2a48f09b[Wrapped task = com.google.gerrit.server.logging.LoggingContextAwareRunnable@248f0ba2]]]-for-SSH git-receive-pack /<repo> (<user>)] INFO  com.googlesource.gerrit.plugins.hooks.HookFactory : hooks.path: /home/gerrit/gerritsite/hooks [CONTEXT RECEIVE_ID="<repo>-1694792901653-3b9e381c" project="<repo>" request="GIT_RECEIVE" ]
[2023-09-15T15:48:21.756Z] [ReceiveCommits-1[java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask@20b09beb[Not completed, task = java.util.concurrent.Executors$RunnableAdapter@2a48f09b[Wrapped task = com.google.gerrit.server.logging.LoggingContextAwareRunnable@248f0ba2]]]-for-SSH git-receive-pack /<repo> (<user>)] INFO  com.googlesource.gerrit.plugins.hooks.HookFactory : hooks.commitReceivedHook resolved to /home/gerrit/gerritsite/hooks/commit-received [CONTEXT RECEIVE_ID="<repo>-1694792901653-3b9e381c" project="<repo>" request="GIT_RECEIVE" ]
[2023-09-15T15:48:21.757Z] [ReceiveCommits-1[java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask@20b09beb[Not completed, task = java.util.concurrent.Executors$RunnableAdapter@2a48f09b[Wrapped task = com.google.gerrit.server.logging.LoggingContextAwareRunnable@248f0ba2]]]-for-SSH git-receive-pack /<repo> (<user>)] DEBUG com.googlesource.gerrit.plugins.hooks.HookExecutor : Hook file not found: /home/gerrit/gerritsite/hooks/commit-received [CONTEXT PLUGIN="hooks" RECEIVE_ID="<repo>-1694792901653-3b9e381c" project="<repo>" request="GIT_RECEIVE" ]
[2023-09-15T15:48:21.774Z] [ReceiveCommits-1[java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask@20b09beb[Not completed, task = java.util.concurrent.Executors$RunnableAdapter@2a48f09b[Wrapped task = com.google.gerrit.server.logging.LoggingContextAwareRunnable@248f0ba2]]]-for-SSH git-receive-pack /<repo> (<user>)] INFO  com.googlesource.gerrit.plugins.hooks.HookFactory : hooks.refUpdatedHook resolved to /home/gerrit/gerritsite/hooks/ref-updated [CONTEXT RECEIVE_ID="<repo>-1694792901653-3b9e381c" project="<repo>" request="GIT_RECEIVE" ]
[2023-09-15T15:48:22.087Z] [SSH git-receive-pack /<repo> (<user>)] INFO  com.google.gerrit.server.git.MultiProgressMonitor : Processing changes: new: 1 (\) [CONTEXT ratelimit_period="1 MINUTES" ]
[2023-09-15T15:48:22.156Z] [ReceiveCommits-1[java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask@20b09beb[Not completed, task = java.util.concurrent.Executors$RunnableAdapter@2a48f09b[Wrapped task = com.google.gerrit.server.logging.LoggingContextAwareRunnable@248f0ba2]]]-for-SSH git-receive-pack /<repo> (<user>)] INFO  com.googlesource.gerrit.plugins.hooks.HookFactory : hooks.patchsetCreatedHook resolved to /home/gerrit/gerritsite/hooks/patchset-created [CONTEXT RECEIVE_ID="<repo>-1694792901653-3b9e381c" project="<repo>" request="GIT_RECEIVE" ]

Kindly suggest me if anything wrong in configuration or if anything else is missing?

Thanks and Regards,
Lokesh

Lokesh Loki

unread,
Sep 17, 2023, 12:22:00 AM9/17/23
to Repo and Gerrit Discussion
Hi , 

Request you to please assist me on this issue

Thanks and Regards,
Lokesh

--
--
To unsubscribe, email repo-discuss...@googlegroups.com
More info at http://groups.google.com/group/repo-discuss?hl=en

---
You received this message because you are subscribed to the Google Groups "Repo and Gerrit Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to repo-discuss...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/repo-discuss/48537d9b-158b-427a-97ef-1ab4f8b90820n%40googlegroups.com.

Lokesh Loki

unread,
Sep 17, 2023, 12:47:15 PM9/17/23
to Repo and Gerrit Discussion
Hi ,

Hooks are getting triggered now. For testing purpose i just kept following lines in the hook script 

#!/bin/bash
source /home/gerrit/gerrit_site/etc/gerrit.config
echo "ref updated" > /home/gerrit/gerrit_site/hooks/test.txt
echo "Gerrit change id : $GERRIT_CHANGE_ID" >> /home/gerrit/gerrit_site/hooks/test.txt
echo "Gerrit project : $GERRIT_PROJECT" >> /home/gerrit/gerrit_site/hooks/test.txt
echo "Gerrit refname : $GERRIT_REFNAME" >> /home/gerrit/gerrit_site/hooks/test.txt
echo "Gerrit change owner email : $GERRIT_CHANGE_OWNER_EMAIL" >> /home/gerrit/gerrit_site/hooks/test.txt

It returned following output by creating test.txt file :
ref updated
Gerrit change id :
Gerrit project :
Gerrit refname :
Gerrit change owner email :

It looks like hook script got triggered and environment variables data are not being displayed. Can you please correct me if am missing something here ?

Thanks and Regards,
Lokesh M

David Charles T M

unread,
Sep 17, 2023, 11:40:24 PM9/17/23
to Lokesh Loki, Repo and Gerrit Discussion
Hi Lokesh,


> It looks like hook script got triggered and environment variables data are not being displayed. Can you please correct me if am missing something here ?

I don't think gerrit has such ENV variables set. You will be able to use GIT env variables[1], if needed. Some variables are passed to the hook by plugin, which you can check in documentation.

#!/bin/bash
# Script to collect hooks arguments
echo "print all passed arguments of $0" >> /home/gerrit/gerrit_site/hooks/test.txt
echo $@ >> /home/gerrit/gerrit_site/hooks/test.txt

[1] https://git-scm.com/book/en/v2/Git-Internals-Environment-Variables

HTH,
Challs
Reply all
Reply to author
Forward
0 new messages