Add GitLab Web hook for all projects in group
That's possible in the enterprise version only:
In GitLab Enterprise Edition you can configure web hooks globally for the whole group. You can add the group level web hooks on the group settings page Settings > Web Hooks.
Following up on @VertigoRay's comments, here's a procedure to do it using GitLab CE API:
Have, or create an user in GitLab and a personal access token with api
scope:
- User (top right avatar) > Settings (menu) > Access tokens (sidebar)
- Check
api
scope (checkbox) - Click on create personal access token (button)
- <my_personal_token> is the value in Your New Personal Access Token (text field)
Perform an HTTP request to get all projects:
GET https://gitlab.example.com/api/v4/projects
Private-Token: <my_personal_token>
Accept: application/json
For each project in the response:
- id which is the <project_ID> to be used in the next request URL
- Convert the value of ssh_url_to_repo so that it becomes URL encoded <encoded_ssh_url>
- Example:
ssh://[email protected]:1234/group/alpha.git
becomesssh%3A%2F%2Fgit%40example.com%3A1234%2Fgroup%2Falpha.git
- Example:
For each project, perform an HTTP request to create a hook:
POST https://gitlab.example.com/api/v4/projects/<project_ID>/hooks
Private-Token: <my_personal_token>
Content-Type: application/json
{
"url": "https://jenkins.example.com/git/notifyCommit?url=<encoded_ssh_url>",
"enable_ssl_verification": true
}
This should be scripted in the langage of your choice.