简体   繁体   中英

How to Configure Gerrit Webhooks for gerrit events

I am trying to perform some actions on gerrit events

  1. When a new repo is added/created.
  2. When a new patch-set is created.
  3. When a change is merged into a specific branch.

The idea is to get event on API endpoint when any of the above happens in any repository.

I have gerrit 3.1.3 installation running on Amazon Linux ec2 instance, and a node server (with open API endpoints) on another similar EC2 Machine. In gerrit config I have added the following lines:

[plugin "webhooks"]
    connectionTimeout = 3000
    socketTimeout = 2500
    maxTries = 300
    retryInterval = 2000
    threadPoolSize = 3
[remote "wh_projectCreated"]
        url = http://17.233.138.23:8080/gereve
        maxTries = 1
        sslVerify = false
        event = patchset-created

I have checked webhooks and hooks plugins are both installed in gerrit installation. Now, I couldn't find a proper blog post which tells how to configure and get gerrit events to be received on webhooks.

What do I need to do more, great help!

You can send a PUT HTTP request to update the webhooks.config file:

curl --location --request PUT '[Gerrit-Site]/a/config/server/webhooks~projects/All-Projects/remotes/[Remote-Name]' \
--header 'Content-Type: application/json; charset=UTF-8' \
--header 'Authorization: Basic aWR...' \
--data-raw '{
    "url" : "https://adbf...43.ngrok.io/api/v1/webhook/e527d4d7-49e5-4699-b780-5b5c8420dc0f",
    "max_tries" : 3,
    "ssl_verify": false,
    "connection_timeout": 10000
  • Make sure to update the webhooks plugin global configuration in gerrit.config.
  • Make sure to include '/a/' in the URL for authenticated requests.

References:

Found the solution, will write down precisely:

  1. In a Folder clone the All-Projects repo (with admin url). git clone "http://admin@<gerrit-address>-:<gerrit-port>/a/All-Projects" .
  2. cd All-Projects/
  3. git fetch origin refs/meta/config:refs/remotes/origin/meta/config
  4. git checkout meta/config
  5. In the root of directory All-Projects , create a file named webhooks.config .
  6. Modify the contents below:
[remote "changemerged"]
  url = http://<webhook-api>:8081/change-merged
  event = change-merged
  
[remote "project_created"]
  url = http://<webhook-api>:8081/create-jenkins-project
  event = project-created

see gerrit-events .

  1. Add and commit the change: git commit -am "Add webhooks config file"

  2. And check in git push origin meta/config:meta/config

and that's it we are done!

(Upvote if you found this helpful)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM