GitLab WebHook Integration
Collect GitLab events (via webhooks), transform them to cdevents.
- GitLab tracks all changes to repositories, issues, merge requests, releases, pipelines, jobs, and more. And it notifies a webhook about these changes.
- cdviz-collector transforms these events to cdevents, and sends them to the database, listeners,...
| From event | CDEvents |
|---|---|
| release.created | artifact.published |
| tag_push | artifact.published |
| push (branch) | branch.{created, deleted} |
| merge_request.open/reopen | change.created |
| merge_request.merge | change.merged |
| merge_request.close | change.abandoned |
| merge_request.approved | change.reviewed |
| merge_request.update | change.updated |
| pipeline.created/pending | pipelineRun.queued |
| pipeline.running | pipelineRun.started |
| pipeline.success/failed | pipelineRun.finished |
| build.running | taskRun.started |
| build.success/failed | taskRun.finished |
| issue.open/reopen | ticket.created |
| issue.close | ticket.closed |
| issue.update | ticket.updated |
Configuration
CDviz Side
Configure cdviz-collector.toml to receive GitLab webhook events:
toml
[sources.gitlab_webhook]
enabled = true
transformer_refs = ["gitlab_events"]
[sources.gitlab_webhook.extractor]
type = "webhook"
id = "000-gitlab" # used as part of the webhook's url
headers_to_keep = ["X-Gitlab-Event"]
[sources.gitlab_webhook.extractor.headers]
# value set by env CDVIZ_COLLECTOR__SOURCES__GITLAB_WEBHOOK__EXTRACTOR__HEADERS__X-GITLAB-TOKEN__VALUE
"x-gitlab-token" = { type = "equals", value = "xxx", case_sensitive = true }
# Transformer from transformers-community repository
[remote.transformers-community]
type = "github://cdviz-dev/transformers-community"
# token = "xxx" # set by env 'CDVIZ_COLLECTOR__REMOTE__TRANSFORMERS-COMMUNITY'
[transformers]
gitlab_events = { type = "vrl", template_rfile = "transformers-community:///gitlab_webhook/transformer.vrl" }Replace "token-changeme" with your actual secret token configured in GitLab webhook settings.
The template_rfile references the VRL transformation logic from the transformers-community repository. For more details on remote transformers, see the Transformers documentation.
The webhook endpoint to declare on GitLab's side is then http://your-collector-url/webhook/000-gitlab.
Testing the access to the webhook
Make an empty POST to the endpoint, it should be rejected with HTTP status 400.
