Make webhook payload variables available in CI/CD rules:if
Everyone can contribute. Help move this issue forward while earning points, leveling up and collecting rewards.
Problem
To assure that newly created projects follows our conventions we would like our Configuration-as-Code tool for GitLab (currently, GitLabForm) to run when a new project is created in the GitLab namespace.
Hence, we want to trigger a Configuration-as-Code pipeline (using GitLabForm) using a webhook when certain changes are made to a group/project (such as project_create, project_destroy, project_rename, project_transfer, project_update). Currently, we can't do this.
Proposal
Make webhook payload such as event_name and path_with_namespace available in the CI/CD rules:if. E.g.
rules:
- if: $WEBHOOK_PAYLOAD_EVENT_NAME == "project_create"
Use case
Note: Ideally we'd like to use Group Hook instead of System Hook but it doesn't seem as if it triggers events for projects events such as project_create, project_destroy, project_rename, project_transfer, project_update (see: #359098).
-
Create a Group Hook (currently, System Hook) for project events (such as create, destroy, rename, transfer and update).
-
The Hook then calls a webhook to trigger a pipeline using API and pipeline trigger token.
-
Pipeline will only start if it is called for a relevant event and/or group/project (checked with rules:if).
However, this is where it stops. GitLab stores the webhook payload in a file. We need the payload to access event_name (create_project) and path_with_namespace (project name) (see System Hooks).
We should also verify secret token (the X-Gitlab-Token HTTP header).
Related issues at GitLab.com
-
#359098 Unclear whether Group Hooks triggers on same projects events as System Hook
- Group Hooks doesn't seem to send events on project changes and using System Hooks to get events on project events is not feasible for a large GitLab instance.
-
#363200 Make webhook payload variables available in CI/CD rules:if
- Even with Group Hooks there are a lot of events being triggered and each can't start a pipeline for us to check if the event is of right type (project change) and right project path.
-
#31197 (closed) Pass webhook POST body to the trigger CI job
- Issue solved by providing (a variable that points to the filename that contains the webhook payload).
- #210389 (comment 912985889) Can't trigger pipeline using webhook outside of GitLab