Trigger a task when a webhook is received¶
saturn server can trigger tasks when it receives webhooks from GitHub or GitLab.
This page describes the setup.
Prerequisites¶
Generate a webhook secret¶
Use Python to generate a random secret:
Record the secret.
GitHub¶
Configure the webhook secret¶
Update the configuration of Saturn:
Restart the server to ensure that the change takes effect.
Create the webhook¶
- Follow Creating a repository webhook to create a webhook for a single repository. Follow Creating an organization webhook to create a webhook for an organization.
- Set Payload URL to
https://$URL/webhooks/github. - Set Content type to application/json.
- Set Secret to the recorded secret.
- Select the events that trigger the webhook.
The
pushevent is the most common event.
Trigger a task when a webhook is received¶
name: "GitHub Webhook Trigger Example"
# ... other settings
trigger:
webhook:
github:
- event: "push" # (1)
filters: # (2)
- '.repository.full_name == "codeberg.org/saturn-sync/saturn"'
- '.ref | startswith("refs/tags/")'
runData: # (3)
tag: '.ref | match("refs\/tags\/(.+)") | .captures[0].string'
- This value must match one of the events selected during Create the webhook. Webhook events and payloads documents all available webhook events.
filtersallow to further select the webhook(s) that trigger a task by inspecting the body of the webhook. Each filter is ajqexpression. Webhook events and payloads documents payloads of webhook events.- Optionally, extract data from the webhook payload and add it as data to the scheduled run.
The key is the key to set in the data of the run.
The value is a
jqexpression that extracts the data.
GitLab¶
Configure the webhook secret¶
Update the configuration of Saturn:
Restart the server to ensure that the change takes effect.
Create the webhook¶
- Follow Create a webhook to create a webhook for a project or group.
- Set URL to
https://$URL/webhooks/gitlab. - Set Secret token to the recorded secret.
- Select the events that trigger the webhook.
The
Push eventis the most common event.
Trigger a task when a webhook is received¶
name: "GitLab Webhook Trigger Example"
# ... other settings
trigger:
webhook:
gitlab:
- event: "Push Hook" # (1)
filters: # (2)
- '.project.path_with_namespace == "mike/diaspora"'
- '.ref == "refs/heads/main"'
runData: # (3)
"branch": '.ref | match("refs\/heads\/(.+)") | .captures[0].string'
- This value must match one of the events selected during Create the webhook. Webhook events documents the events.
filtersallow to further select the webhook(s) that trigger a task by inspecting the body of the webhook. Each filter is ajqexpression. Webhook events documents payloads of webhook events.- Optionally, extract data from the webhook payload and add it as data to the scheduled run.
The key is the key to set in the data of the run.
The value is a
jqexpression that extracts the data.