Skip to content

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,...

CDEventsFrom event
pipelineRun.queuedpipeline.created/pending
pipelineRun.startedpipeline.running
pipelineRun.finishedpipeline.success/failed
taskRun.startedbuild.running
taskRun.finishedbuild.success/failed
artifact.publishedrelease.created
artifact.publishedtag_push
ticket.createdissue.open/reopen
ticket.closedissue.close
ticket.updatedissue.update
change.createdmerge_request.open/reopen
change.mergedmerge_request.merge
change.abandonedmerge_request.close
change.reviewedmerge_request.approved
change.updatedmerge_request.update
branch.created/deletedpush (branch)

Configuration ​

Setting Up cdviz-collector ​

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-pro repository
[remote.transformers-pro]
type = "github"
owner = "cdviz-dev"
repo = "transformers-pro"
# token = "xxx"  # set by env 'CDVIZ_COLLECTOR__REMOTE__TRANSFORMERS-PRO'

[transformers]
gitlab_events = { type = "vrl", template_rfile = "transformers-pro:///gitlab_events/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-pro repository. For more details on remote transformers, see the Transformers documentation.

Testing the access to the webhook ​

Make an empty POST to the endpoint, it should be rejected with HTTP status 400.

❯ curl -i -X POST https://demo.cdviz.dev/webhook/000-gitlab -H 'X-Gitlab-Token: xxxxxxx'

HTTP/2 400
...
Failed to parse the request body as JSON

Setting Up GitLab Webhook ​

Configure a webhook in your GitLab project or group:

  1. Navigate to Settings > Webhooks
    • For projects: https://gitlab.com/<namespace>/<project>/-/hooks
    • For groups: https://gitlab.com/groups/<group>/-/hooks
  2. Click Add new webhook
  3. URL: http://your-collector-url/webhook/000-gitlab
  4. Secret token: Enter the token from your collector configuration (the same as value for header x-gitlab-token defined in the configuration)
  5. Select Trigger events:
    • βœ… Push events
    • βœ… Tag push events
    • βœ… Issues events
    • βœ… Confidential issues events
    • βœ… Merge request events
    • βœ… Job events
    • βœ… Pipeline events
    • βœ… Deployment events
    • βœ… Release events
    • βœ… Vulnerability events
  6. Enable SSL verification (recommended for production)
  7. Ensure Enable webhook is checked
  8. Click Add webhook

Testing the Integration ​

Test webhook delivery: use the Test button

Check webhook delivery logs in GitLab: Settings > Webhooks > Edit > Recent events

To verify webhook reception before transformation:

toml
[sources.gitlab_webhook]
transformer_refs = ["log", "discard_all"]  # Log payloads without processing

For webhook troubleshooting, see the Webhook Extractor documentation.

Event Mapping ​

The transformer converts GitLab webhook events into CDEvents following the CDEvents specification:

GitLab EventCDEvent TypeDetection Logic
pipeline:created/pendingpipelineRun.queuedobject_kind=pipeline AND status in [created, waiting_for_resource, preparing, pending]
pipeline:runningpipelineRun.startedobject_kind=pipeline AND status=running
pipeline:success/failedpipelineRun.finishedobject_kind=pipeline AND status in [success, failed, canceled, skipped]
build:runningtaskRun.startedobject_kind=build AND build_status=running
build:success/failedtaskRun.finishedobject_kind=build AND build_status in [success, failed, canceled]
release:createdartifact.publishedobject_kind=release
tag_pushartifact.publishedobject_kind=tag_push AND tag created
issue:open/reopenticket.createdobject_kind=issue AND action in [open, reopen]
issue:closeticket.closedobject_kind=issue AND action=close
issue:updateticket.updatedobject_kind=issue AND other actions
merge_request:open/reopenchange.createdobject_kind=merge_request AND action in [open, reopen]
merge_request:mergechange.mergedobject_kind=merge_request AND action=merge
merge_request:closechange.abandonedobject_kind=merge_request AND action=close (not merged)
merge_request:approvedchange.reviewedobject_kind=merge_request AND action=approved
merge_request:updatechange.updatedobject_kind=merge_request AND other actions
push (branch)branch.created/deletedobject_kind=push AND ref starts with refs/heads/

CDEvent Structure ​

The VRL transformation generates CDEvents with:

  • context.id: Auto-generated by collector
  • context.source: Automatically set to {http.root_url}/?source={source_name} where {source_name} is the configuration key (e.g., gitlab_webhook)
  • subject.id: Web URL of the entity (pipeline, job, issue, MR) or PURL for artifacts
  • subject.source: Empty (not set)
  • customData.gitlab: Selected GitLab-specific metadata (project, user, event-specific details)

Artifact Identification ​

For artifact.published events, the subject.id is a PURL (Package URL):

  • Release: pkg:generic/<project_path>@<tag_name>?repository_url=<encoded_url>
  • Tag Push: pkg:generic/<project_path>@<tag_name>?repository_url=<encoded_url>

Event Coverage ​

Supported Events:

  • βœ… Pipeline lifecycle (queued, started, finished)
  • βœ… Job lifecycle (started, finished)
  • βœ… Issues (created, updated, closed)
  • βœ… Merge requests (created, updated, merged, abandoned, reviewed)
  • βœ… Releases and tags (artifact published)
  • βœ… Branch operations (created, deleted)

Not Yet Supported:

  • Deployment events β†’ service.deployed
  • Wiki page events
  • Comment events
  • Confidential issues/MRs
  • System hooks

These can be added following the existing pattern in the transformer VRL file.