# Webhooks
Sun* CI allow you to setup webhooks for repository. When the build is finished, we'll send a HTTP POST payload to the webhook's configured URL. Webhooks can be used to set up notifications or something else.
# Add webhooks
You can find your webhooks settings at project settings page.
# Event
Below are described the supported events.
# Build event
Triggered when a build was finished.
Available build.status
:
passed
failed
canceled
running
Webhook payload object
Key | Type | Description |
---|---|---|
event | string | Most webhook payloads contain an event property that contains the specific activity that triggered the event. |
build | object | Build's information such as status, event from github, jobs, ... |
repository | object | The repository where the event occurred. Webhook payloads contain the repository property when the event occurs from activity in a repository. |
Payload example
{
"event": "build",
"build": {
"id": 573924,
"repository_id": 78518,
"number": 97,
"status": "passed",
"event": "push",
"action": "create",
"branch": "master",
"ref": "master",
"pr_number": null,
"commit": "77489c7a35378fa943f0afd95102c576f4ab8842",
"message": "Update .sun-ci.yml",
"message_title": "Update .sun-ci.yml",
"message_body": "",
"link": "https://github.com/xxxx/xxxx/commit/77489c7a35378fa943f0afd95102c576f4ab8842e",
"author": "xxxx",
"sender": "xxxx",
"sender_avatar": "https://avatars.githubusercontent.com/u/7238715741?v=4",
"duration": 95,
"config_error": false,
"config_warning": true,
"started_at": "2022-10-11T08:55:36+07:00",
"finished_at": "2022-10-11T08:57:11+07:00",
"created_at": "2022-10-11T08:55:31+07:00",
"updated_at": "2022-10-11T08:57:11+07:00"
},
"repository": {
"id": 78518,
"scm": "github",
"namespace": "xxxx",
"name": "xxxx"
}
}
# Release event
Triggered when your build is finish and has release job.
Available build.status
:
passed
failed
canceled
running
Webhook payload object
Key | Type | Description |
---|---|---|
event | string | Most webhook payloads contain an event property that contains the specific activity that triggered the event. |
build | object | Build's information |
release | object | Contain information such as enviroment, url, jobs |
repository | object | The repository where the event occurred. Webhook payloads contain the repository property when the event occurs from activity in a repository. |
Payload example
{
"event": "release",
"build": {
"id": 5656,
"repository_id": 8898,
"number": 72,
"status": "passed",
"message": "Release passed on Sun* CI",
"event": "pull_request",
"action": "opened",
"branch": "master",
"ref": "refs/pull/33/head",
"pr_number": 33,
"commit": "3df5a5e9e2c5f807f169ddb023cec40c57a650bf",
"message": "feat(api): add more release",
"message_title": "feat(api): add more release",
"message_body": null,
"link": "https://github.com/sun-ci/sun-ci-repo/pull/33",
"author": "sun-ci",
"sender": "sun-ci",
"sender_avatar": "https://avatars.githubusercontent.com/u/78715700?v=4",
"duration": 126,
"config_error": false,
"config_warning": false,
"started_at": "2021-07-13T15:23:42+07:00",
"finished_at": "2021-07-13T15:25:48+07:00",
"created_at": "2021-07-13T15:21:46+07:00",
"updated_at": "2021-07-13T15:25:48+07:00"
},
"release": {
"environment": "production",
"url": "https://ci.sun-asterisk.com",
"job": {
"name": "Say bye again!",
"stage": {
"id": 17087,
"build_id": 5656,
"name": "Test",
"status": "passed",
"created_at": "2021-07-13T08:21:46.000000Z",
"updated_at": "2021-07-13T08:25:48.000000Z",
"number": 3
},
"status": "passed",
"status_message": "Release passed on Sun* CI",
"started_at": "2021-07-13T15:25:36+07:00",
"finished_at": "2021-07-13T15:25:48+07:00"
}
},
"repository": {
"id": 8898,
"scm": "github",
"namespace": "sun-ci",
"name": "sun-ci-repo"
}
}
# Test result event
Triggered when your build has config test_result
or
coverage
.
Webhook payload object
Key | Type | Description |
---|---|---|
event | string | Most webhook payloads contain an event property that contains the specific activity that triggered the event. |
build | object | Build's information |
test_result | object | Contain information such as code coverage, test result |
repository | object | The repository where the event occurred. Webhook payloads contain the repository property when the event occurs from activity in a repository. |
Payload example
{
"event": "test_result",
"build": {
"id": 573924,
"repository_id": 785118,
"number": 97,
"status": "passed",
"event": "push",
"action": "create",
"branch": "master",
"ref": "master",
"pr_number": null,
"commit": "77489c7a35378fa943f0afd95102c57z6f4ab8e842",
"message": "Update .sun-ci.yml",
"message_title": "Update .sun-ci.yml",
"message_body": "",
"link": "https://github.com/xxxx/xxxx/commit/77489c7a35378fa943f0afd95102c576f4ab8842e",
"author": "author",
"sender": "sender",
"sender_avatar": "https://avatars.githubusercontent.com/u/7238715741?v=4",
"duration": 95,
"config_error": false,
"config_warning": true,
"started_at": "2022-10-11T08:55:36+07:00",
"finished_at": "2022-10-11T08:57:11+07:00",
"created_at": "2022-10-11T08:55:31+07:00",
"updated_at": "2022-10-11T08:57:11+07:00"
},
"test_result": {
"id": 146618,
"tests": 90,
"assertions": 153,
"errors": 0,
"warnings": 0,
"failures": 0,
"skipped": 0,
"time": "7.193198",
"coverage": "18.98",
"last_coverage": "18.98",
"line": 1117,
"covered_line": 212,
"method": 255,
"covered_method": 59,
"branch": 0,
"covered_branch": 0,
"created_at": "2022-10-11T08:57:56+07:00",
"updated_at": "2022-10-11T08:57:56+07:00"
},
"repository": {
"id": 785118,
"scm": "github",
"namespace": "xxxx",
"name": "xxxx"
}
}
# Sample notifications using Slack Forwarder
This is a example send notifications to Slack with Sun* CI payload. Perform the following steps to enable Slack notifications:
Go to Slack Forwarder page and login.
In the left sidebar, select Webhooks ->
Create
.Enter webhook name, go to slack chanel to add slack forwarder app and copy chanel id ->
Save
You need to create payloads for webhooks too, go down to payloads section chose
Create
.Enter payload params for build/release event above and enter content you want to show in Slack or just copy this content below ->
Create/Save
.
TO ALL >>>
[info][title] Build {!! $params.build.status !!} on Sun* CI [/title]
Event: {!! $params.build.event !!}
Branch: {!! $params.build.branch !!}
Status: {!! $params.build.status !!}
Message: {!! $params.build.message !!}
{!! $params.build.message_title !!}
Link: https://ci.sun-asterisk.com/github/{!! $params.build.repository.namespace !!}/{!! $params.build.repository.name !!}/builds/{!! $params.build.number !!}
[/info]
Copy webhook url and redirect to Sun* CI project settings page.
Create new webhook with slack forwarder url.
If you using our content example when setting Slack Forwarder, Slack notifications will look like: