Manage repository webhooks using web UI¶
You must have admin privileges to the repository to create a webhook or edit any aspect of an existing webhook.
Create a webhook for your repository¶
In your browser, navigate to
https://<msr-url>
and log in with your credentials.Select Repositories from the left-side navigation panel, and then click the name of the repository that you want to view. Note that you will have to click the repository name following the
/
after the specific namespace for your repository.Select the Webhooks tab, and click New Webhook.
From the Notification to receive drop-down list, select the event that will trigger the webhook.
Set the URL that will receive the JSON payload.
Validate the integration by clicking the Test button next to the Webhook URL field. If the integration is working, you will receive a JSON payload at the URL you specified for the event type notification you selected.
Example output:
{ "type": "TAG_PUSH", "createdAt": "2019-05-15T19:39:40.607337713Z", "contents": { "namespace": "foo", "repository": "bar", "tag": "latest", "digest": "sha256:b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b878ae4944c", "imageName": "foo/bar:latest", "os": "linux", "architecture": "amd64", "author": "", "pushedAt": "2015-01-02T15:04:05Z" }, "location": "/repositories/foo/bar/tags/latest" }
Optional. Assign a TLS certificate to your webhook:
Expand Show advanced settings.
Paste the TLS certificate associated with your webhook URL into the TLS Cert field.
Note
For testing purposes, you can test your TLS certificate over HTTP rather than HTTPS.
To circumvent TLS verification, tick the Skip TLS Verification checkbox.
Optional. Format your webhook message:
You can use Golang templates to format the webhook messages that are sent.
Expand Show advanced settings.
In the Webhook Message Format field, paste the configured Golang template for the webhook message.
Click Create to save the webhook. Once saved, your webhook is active and starts sending POST notifications whenever your selected event type is triggered.
As a repository admin, you can add or delete a webhook at any point. Additionally, you can create, view, and delete webhooks for your organization or trusted registry using the API.
Change webhook status¶
Note
By default, the webhook status is set to Active on its creation.
In your browser, navigate to
https://<msr-url>
and log in with your credentials.Select Repositories from the left-side navigation panel, and then click the name of the repository that you want to view. Note that you will have to click the repository name following the
/
after the specific namespace for your repository.Select the Webhooks tab. The existing webhooks display on the page.
Locate the webhook for which you want to change the status and move the slider underneath the Active heading accordingly.
Format webhook messages¶
You can use Golang TemplatesOverview
to dynamically format webhook
messages. This feature enables you to personalize webhook messages based
on your needs.
Create a template¶
Create your webhook message template using Golang syntax:
In the Webhooks tab, expand Show advanced settings.
In the Webhook Message Format field, configure Golang template for the webhook message.
Define variables and control structures for the system to make templates dynamic. Defined variables are replaced with their respective values during the creation of the webhook message. You can also use standard Golang functions to manipulate the values of the variables.
Click Create to save the webhook. Once saved, your webhook is active and starts sending POST notifications whenever your selected event type is triggered.
Format a message¶
For the Tag push
event, use the following format:
{ "message" : "Tag {{ .Contents.Tag }} was pushed for repository {{ .Contents.Repository }}" }
Example output:
{ "message" : "Tag 1.0 was pushed for repository example_repo" }
The variables used in the template are defined in the webhook message
and are enclosed in double curly braces.
For example, the variable .Tag
is replaced with the value of
the Tag
field in the webhook message.
Add conditional logic¶
Control structures are used to add conditional logic to the template.
For instance, you can use an if
statement to verify the value of a field:
{{ if eq .Contents.Name "test" }}
{ "message" : "The Name field is test" }
{{ end }}
Every field in the webhook message is accessible through Golang template in the
webhook format field. This includes fields such as .Type
, .CreatedAt
,
.Location
, and the nested fields within .Contents
.
Refer to Create a webhook for your repository for more details.