Navigate to Administration Module | General | Webhooks and click New Webhook:
Click the Custom toggle.
Enter the details of the following fields:
Field
Description
URL
Specifies the URL that the Webhook invokes. This will be the URL that Artifactory will send an HTTP POST request to.
Example:
https://api.github.com/repos/myrepo/actions/workflows/artifact_deployed.yml/dispatches
Event
Displays the list of Events in Artifactory, Xray, and Distribution that function as the event trigger for the Webhook.
Secrets
Defines a set of sensitive values (such as, tokens and passwords) that can be injected in the headers and/or payload.Secrets’ values are encrypted.
In the header/payload, the value can be invoked using the
{{.secrets.token}}
format, wheretoken
is the name provided for the secret value.Click Add Secret to add more than one secret.
Note
It is possible to update the value of a secret (when a password changes, or a token expires) using the Update Webhook Subscription by Key REST API:
PUT /event/api/v1/subscriptions/<sub-key>/secrets/<secret-name>
Authorization: Bearer <admin token>
Content-Type: text/plain
<secret-value>
Headers
Adds HTTP headers you wish to use to invoke the Webhook.
Click Add Header to add more than one header.
Payload
The custom payload you want to send to the target service.
In the payload, values can be invoked using dotted-syntax.
Example
{ "ref": "main", "inputs": { "artifact_path": "{{.data.repo_key}}/{{.data.path}}" } }
To know what values can be injected in the payload (as well as in HTTP headers), see the Event Types section below.
Optionally, you can click Test to send a fake HTTP request to the target URL and verify that the webhook is working fine.
Click Create.
Examples
The following are some examples of custom webhooks for various services.
GitHub Example
{ "key": "subscriptionOnGithub", "description": "some custom webhook subscription", "enabled": true, "event_filter": { "criteria": { "anyLocal": true }, "domain": "artifact", "event_types": [ "deployed" ] }, "handlers": [ { "handler_type": "custom-webhook", "url": "https://api.github.com//<username>/<reponame>/dispatches", "payload": "{\"event_type\": \"someEventType\"}", "secrets": [ { "name": "token", "value": "XXX" } ], "http_headers": [ { "name": "Authorization", "value": "Bearer {{ .secrets.token }}" } ] } ] }
GitLab Example
{ "key": "subscriptionOnGitlab", "description": "some custom webhook subscription", "enabled": true, "event_filter": { "domain": "artifact", "event_types": [ "deployed" ], "criteria": { "anyLocal": true, "anyRemote": false, "includePatterns": [], "excludePatterns": [], "repoKeys": [] } }, "handlers": [ { "handler_type": "custom-webhook", "url": "http://<gitlaburl>/api/v4/projects/2/ref/main/trigger/pipeline", "secrets": [ { "name": "privatetoken", "value": "XXXXX" }, { "name": "accesstoken", "value": "XXXXXX" }, { "name": "token", "value": "XXXXXXX" } ], "http_headers": [ { "name": "PRIVATE-TOKEN", "value": "{{ .secrets.privatetoken }}" }, { "name": "Content-Type", "value": "application/x-www-form-urlencoded" } ], "payload": "token={{ .secrets.token }}&variables[TEST_VAR_CHECKSUM]={{ .data.sha256 }}&variables[ACCESS_TOKEN]={{ .secrets.accesstoken }}" } ] }
Jenkins Example
{ "key": "subscriptionOnJenkins", "description": "some custom webhook subscription", "enabled": true, "event_filter": { "criteria": { "anyLocal": true }, "domain": "artifact", "event_types": [ "deployed" ] }, "handlers": [ { "handler_type": "custom-webhook", "url": "http://<jenkinsurl>/job/test/buildWithParameters", "secrets": [ { "name": "token", "value": "mytoken" }, { "name": "restapitoken", "value": "XXXXX" } ], "http_headers": [ { "name": "Content-Type", "value": "application/x-www-form-urlencoded" }, { "name": "Authorization", "value": "Basic {{ .secrets.restapitoken }}" } ], "payload": "token={{ .secrets.token }}&sha256={{ .data.sha256 }}" } ] }
Slack Integration Example
{ "key": "customwebhook", "description": "notify slack channel at artifact deploy", "enabled": true, "event_filter": { "domain": "artifact", "event_types": [ "deployed" ], "criteria": { "anyLocal": true, "anyRemote": false, "excludePatterns": [], "includePatterns": [], "repoKeys": [] } }, "handlers": [ { "handler_type": "custom-webhook", "url": "https://hooks.slack.com/services/XXXX", "payload": "{\"text\": \"Hello from custom webhook triggered by event type {{ .type }}\"}", "http_headers": [ { "name": "Content-type", "value": "application/json" } ] } ] }