unity cloud_Unity Cloud Build中的Webhooks和Slack通知

unity cloud

Unity Cloud Build is a continuous integration service for games and apps built in Unity. Unity Cloud Build makes it simple and easy to create and share builds of your game, letting you and your team iterate faster and always be on the same page. Setting up Unity Cloud Build takes seconds and works with your existing source control repository.

Unity Cloud Build 是针对Unity内置的游戏和应用程序的持续集成服务。 Unity Cloud Build使创建和共享游戏版本变得简单容易,让您和您的团队可以更快地迭代,并且始终在同一页面上 。 设置Unity Cloud Build只需几秒钟,即可与您现有的源代码控制存储库一起使用。

Unity Cloud Build now supports webhooks! Webhooks are a simple and flexible way to receive event notifications in near-real time. In this article, we’ll discuss webhooks in more depth, what kind of events are supported, and how to configure webhooks using the Unity Cloud Build API.

Unity Cloud Build现在支持webhooks! Webhooks是一种简单且灵活的方式,可以近实时地接收事件通知。 在本文中,我们将更深入地讨论webhooks,支持哪些事件,以及如何使用Unity Cloud Build API配置webhooks。

什么是网络钩子? (What are webhooks?)

Webhooks are event callbacks from Unity Cloud Build, where Unity servers send messages to your web servers to let them know what’s happening. We do this using HTTP POST to deliver a payload related to the event that triggered the callback. Currently, Unity Cloud Build triggers events related to build status updates. Over time we will be expanding these notifications to include events related to project configuration changes, permission changes, and many more.

Webhooks是Unity Cloud Build中的事件回调,Unity服务器在其中将消息发送到Web服务器,以使他们知道发生了什么。 我们使用HTTP POST来执行此操作,以传递与触发回调的事件相关的有效负载。 当前,Unity Cloud Build触发与 构建状态 更新 相关的事件 。 随着时间的推移,我们将扩展这些通知,以包括与项目配置更改,权限更改等相关的事件。

Unity Cloud Build supports hooks at both the Organization level and Project level. Organization level hooks are sent for events related to all projects belonging to an organization. Project level hooks are only sent for events related to a specific project. While both types of hooks are nearly identical in configuration, we will focus on Project level events for this tutorial; to read more about organization hooks, see the Cloud Build API Documentation.

Unity Cloud Build支持 组织 级别和 项目 级别的 挂钩 。 发送 组织 级挂钩,以获取与 属于组织的 所有 项目 有关的事件 。 仅针对与特定项目相关的事件发送 项目 级别挂钩。 尽管两种类型的挂钩在配置上几乎相同,但在本教程中,我们将重点关注项目级别的事件。 要了解有关组织挂钩的更多信息,请参阅 Cloud Build API文档

支持的活动 (Supported Events)
EventTrigger Condition
ProjectBuildQueuedWhen a build target is queued for building
ProjectBuildStartedWhen a build starts
ProjectBuildRestartedWhen an internal error occurs and the job is restarted
ProjectBuildSuccessWhen a build finishes successfully
ProjectBuildFailureWhen a build finishes with a failure condition
ProjectBuildCanceledWhen a build in progress is canceled
事件 触发条件
ProjectBuild已排队 当构建目标排队等待构建时
ProjectBuildStarted 构建开始时
重新启动ProjectBuild 当发生内部错误并重新启动作业时
ProjectBuild成功 构建成功完成后
ProjectBuild失败 当构建因故障而结束时
已取消ProjectBuild 取消进行中的构建时
Webhook负载 (Webhook payload)

A webhook delivery includes detailed information related to the delivery event (HTTP headers) and the new resource state (HTTP body) of the resource related to the event. In the case of project build events, the state of a build in progress is included as the payload.

Webhook传递包括与 传递事件 (HTTP标头) 有关的详细信息以及与该 事件 有关的 资源 的新 资源状态 (HTTP正文)。 对于项目构建事件,正在进行的构建状态将作为有效负载包括在内。

Event Headers

活动标题

NameDescription
X-UnityCloudBuild-HookIdThe record ID of the hook
X-UnityCloudBuild-EventThe name of the event that triggered this hook
X-UnityCloudBuild-DeliveryIdA unique UUID that identifies this delivery instance
X-UnityCloudBuild-SignatureThe SHA256 HMAC signature of the payload when a secret is defined
名称 描述
X-UnityCloudBuild-HookId 挂钩的记录ID
X-UnityCloudBuild-Event 触发此挂接的事件的名称
X-UnityCloudBuild-DeliveryId 唯一标识此交付实例的UUID
X-UnityCloudBuild-签名 定义机密时有效负载的SHA256 HMAC签名


Example Delivery

交货示例

1

2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
POST / HTTP/1.1
X-UnityCloudBuild-Event: ProjectBuildQueued
X-UnityCloudBuild-HookId: 7
X-UnityCloudBuild-DeliveryId: 81a4ab67-0176-4e4c-8ab2-bd0ab7d3cc70
Content-Type: application/json
{
   "projectName":"My Project",
   "buildTargetName":"Mac desktop 32-bit build",
   "projectGuid":"0895432b-43a2-4fd3-85f0-822d8fb607ba",
   "orgForeignKey":"13260",
   "buildNumber":14,
   "buildStatus":"queued",
   "startedBy":"Build User <builduser@domain.com>",
   "platform":"standaloneosxintel",
   "links":{
      "api_self":{
         "method":"get",
         "href":"..."
      },
      "dashboard_url":{
         "method":"get",
         "href":"..."
      },
      "dashboard_project":{
         "method":"get",
         "href":"..."
      },
      "dashboard_summary":{
         "method":"get",
         "href":"..."
      },
      "dashboard_log":{
         "method":"get",
         "href":"..."
      }
   }
}

1

2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
POST / HTTP / 1.1
X - UnityCloudBuild - Event : ProjectBuildQueued
X - UnityCloudBuild - HookId : 7
X - UnityCloudBuild - DeliveryId : 81a4ab67 - 0176 - 4e4c - 8ab2 - bd0ab7d3cc70
Content - Type : application / json
{
   "projectName" : "My Project" ,
   "buildTargetName" : "Mac desktop 32-bit build" ,
   "projectGuid" : "0895432b-43a2-4fd3-85f0-822d8fb607ba" ,
   "orgForeignKey" : "13260" ,
   "buildNumber" : 14 ,
   "buildStatus" : "queued" ,
   "startedBy" : "Build User <builduser@domain.com>" ,
   "platform" : "standaloneosxintel" ,
   "links" : {
       "api_self" : {
         "method" : "get" ,
         "href" : "..."
       } ,
       "dashboard_url" : {
         "method" : "get" ,
         "href" : "..."
       } ,
       "dashboard_project" : {
         "method" : "get" ,
         "href" : "..."
       } ,
       "dashboard_summary" : {
         "method" : "get" ,
         "href" : "..."
       } ,
       "dashboard_log" : {
         "method" : "get" ,
         "href" : "..."
       }
   }
}

创建和管理网络挂钩 (Creating and managing webhooks)

You can add webhooks to your project from the Unity Cloud Build website. Visit your project’s history page, then click on the “Notifications” tab.

您可以从Unity Cloud Build网站向您的项目添加webhooks。 访问您的项目的历史记录页面,然后单击“通知”选项卡。

image01
image02

From here you can enter the URL on your web server that’s been configured to accept webhooks, and select which types of events you’d like to be notified about.

在这里,您可以输入已配置为接受Webhook的Web服务器上的URL,并选择您想要收到通知的事件类型。

通知松弛 (Slack notifications)

If your team uses Slack for communication, you know how powerful incoming webhooks can be and would probably love to see these build events from Cloud Build integrated into your workflow. We’ve got you covered! From your project’s Notifications page, you can also configure Unity Cloud Build to send notifications to a specific channel in Slack.

如果您的团队使用Slack进行通信,您会知道传入的Webhooks有多么强大,并且可能希望看到将Cloud Build中的这些构建事件集成到您的工作流程中。 我们已经覆盖了您! 从项目的“通知”页面,您还可以配置Unity Cloud Build以将通知发送到Slack中的特定通道。

Click the “Add to Slack” button, which will prompt you to log into your team’s Slack service, then pick the specific user or channel that you’d like notifications sent to. The build notifications look like this, including the status of the build and a link directly to the project:

image00

点击“添加到Slack”按钮,这将提示您登录团队的Slack服务,然后选择要将通知发送到的特定用户或频道。 构建通知如下所示,包括构建状态和直接指向项目的链接:

进阶:使用Unity Cloud Build API的webhooks (Advanced: webhooks using the Unity Cloud Build API)

You can also use the Unity Cloud Build API to create, view, and modify webhooks. For these examples, we will use CURL to send requests to the API to setup a new webhook. To get started, you will need your Unity Cloud Build API key, which you can find on the preferences page of the Unity Cloud Build website.

您还可以使用 Unity Cloud Build API 来创建,查看和修改webhook。 对于这些示例,我们将使用CURL向API发送请求以设置新的Webhook。 首先,您需要Unity Cloud Build API密钥,您可以 在Unity Cloud Build网站 的 首选项页面 上 找到该密钥 。

创建一个项目webhook (Creating a project webhook)

To add a project webhook, you’ll need a few pieces of information to build the API call. First, find the orgid and projectid of your project. These can be found in the URL of the project’s history page on the Cloud Build website:

要添加项目Webhook,您需要一些信息来构建API调用。 首先,找到 您的项目 的 orgidprojectid 。 这些可以在Cloud Build网站上项目历史记录页面的URL中找到:

image03

API Request

API请求

1

POST /api/orgs/{orgid}/projects/{projectid}/hooks

1

POST / api / orgs / { orgid } / projects / { projectid } / hooks

Request Parameters

请求参数

NameTypeDescription
hookTypestring(Required) Type of hook. This should be web for now – other hook types will be coming in the future.
eventsarray(Required) List of events to listen to for this hook. See event table above for the complete list.
configobject(Required) Configuration parameters. Options are described below.
名称 类型 描述
hookType (必需)挂钩类型。 现在 应该是 网络 -将来还会有其他钩子类型。
大事记 数组 (必需)要侦听此挂钩的事件列表。 有关完整列表,请参见上面的事件表。
配置 目的 (必需)配置参数。 选项说明如下。

Configuration Options

配置选项

NameTypeDescription
urlstring(Required) HTTP or HTTPS endpoint to send hook payloads
encodingstring(Default: “json”) Either json or form, depending on the desired POST body format.
sslVerifyboolean(Default: true) Verify SSL certificates of SSL endpoints.
secretstringIf set, used to compute the SHA256 HMAC signature of the hook body and adds a X-UnityCloudBuild-Signature header to the payload. Useful to validates authenticity of requests when sending to a non-SSL (HTTP) endpoint.
名称 类型 描述
网址 (必需)HTTP或HTTPS端点以发送挂钩有效负载
编码方式 (默认值:“ json”) jsonform ,取决于所需的POST正文格式。
ssl验证 布尔值 (默认值:true)验证SSL端点的SSL证书。
秘密 如果设置,则用于计算钩子主体的SHA256 HMAC签名,并将X-UnityCloudBuild-Signature标头添加到有效负载。 发送到非SSL(HTTP)端点时,对验证请求的真实性很有用。

Example Request Body

请求正文示例

1

2
3
4
5
6
7
8
9
10
11
{
  "hookType": "web",
  "events": [
    "ProjectBuildStarted",
    "ProjectBuildSuccess",
    "ProjectBuildFailure"
  ],
  "config": {
    "url": "http://requestb.in/1go1tjj1"
  }
}

1

2
3
4
5
6
7
8
9
10
11
{
   "hookType" : "web" ,
   "events" : [
     "ProjectBuildStarted" ,
     "ProjectBuildSuccess" ,
     "ProjectBuildFailure"
   ] ,
   "config" : {
     "url" : "http://requestb.in/1go1tjj1"
   }
}
放在一起-以CURL为例 (Putting it all together – example with CURL)

Here is an example of creating a webhook with CURL. This is tested on MacOS; on other platforms you may have to make slight modifications.

这是使用CURL创建Webhook的示例。 这已在MacOS上进行了测试; 在其他平台上,您可能需要进行一些修改。

1

2
3
4
5
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer [YOUR API KEY]" \
-d '{"hookType":"web","events":["ProjectBuildStarted","ProjectBuildSuccess","ProjectBuildFailure"],"config":{"url":"http://requestb.in/1go1tjj1"}}' \
https://build-api.cloud.unity3d.com/api/orgs/[YOUR ORGID]/projects/[YOUR PROJECTID]/hooks

1

2
3
4
5
curl - X POST \
- H "Content-Type: application/json" \
- H "Authorization: Bearer [YOUR API KEY]" \
- d '{"hookType":"web","events":["ProjectBuildStarted","ProjectBuildSuccess","ProjectBuildFailure"],"config":{"url":"http://requestb.in/1go1tjj1"}}' \
https : //build-api.cloud.unity3d.com/api/orgs/[YOUR ORGID]/projects/[YOUR PROJECTID]/hooks

Response

响应

1

2
3
4
5
6
7
8
9
10
11
12
13
14
15
{
  "hookType": "web",
  "events": [
"ProjectBuildStarted",
"ProjectBuildSuccess",
"ProjectBuildFailure"
  ],
  "config": {
"encoding": "json",
"sslVerify": true,
"url": "http://requestb.in/1go1tjj1"
  },
  "active": true,
  "id": 0
}

1

2
3
4
5
6
7
8
9
10
11
12
13
14
15
{
   "hookType" : "web" ,
   "events" : [
"ProjectBuildStarted" ,
"ProjectBuildSuccess" ,
"ProjectBuildFailure"
   ] ,
   "config" : {
"encoding" : "json" ,
"sslVerify" : true ,
"url" : "http://requestb.in/1go1tjj1"
   } ,
   "active" : true ,
   "id" : 0
}

That’s it! You have successfully setup a webhook for your project. To test it out, start a new build and monitor the logs for your webhook request endpoint. If you are using RequestBin for testing, simply reload the page for the RequestBin URL to refresh the request history.

而已! 您已经为项目成功设置了一个Webhook。 要对其进行测试,请开始一个新的构建并监视您的Webhook请求端点的日志。 如果您使用RequestBin进行测试,只需重新加载RequestBin URL的页面即可刷新请求历史记录。

To learn more about using the API to manage webhooks, including listing, removing, and editing, refer to the Webhooks section of the Cloud Build API documentation.

要了解更多关于使用API来管理网络挂接,包括上市,删除和编辑,请参阅 网络挂接部分 中的 云构建API文档

结论 (Conclusion)

Webhooks are a powerful tool to help you deeply integrate Unity Cloud Build into your development process. Webhooks are accessible now through the Unity Cloud Build API and web dashboard. If you have thoughts on what kinds of events you would like to see next for Webhooks, or if you would really like to see other custom webhook types like Slack, please share your thoughts here in the comments section!

Webhooks是一个功能强大的工具,可帮助您将Unity Cloud Build深度集成到开发过程中。 现在可以通过Unity Cloud Build API和Web仪表板访问Webhooks。 如果您对接下来要针对Webhooks看到的事件有任何想法,或者如果您真的希望看到Slack等其他自定义Webhook类型,请在评论部分中分享您的想法!

Unity Cloud Build is built right into Unity, and included in Unity Personal, Plus, and Pro. Click here to get started now for free!

Unity Cloud Build直接内置在Unity中,并包含在Unity Personal,Plus和Pro中。 单击此处免费开始!

翻译自: https://blogs.unity3d.com/2016/09/07/webhooks-and-slack-notifications-in-unity-cloud-build/

unity cloud

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值