LoginSignup
6
5

More than 5 years have passed since last update.

UnityCloudBuildにNotificationsタブが増えてWebhooksが使えるようになっていた

Posted at

はじめに

UnityCloudBuildを使った時に、開始時や終了時の通知をする方法は、メールかOnPostProcessBuildを使うか、WebApiで監視するかしかないと思っていましたが、
設定を見ていると、Webhooksが使えるようになっていたので、試してみました。

注意

  • 特定できそうな英数字は0に置換
  • 1行のものでも、見やすいように適当なところで改行

参考
Webhooks API documentation

設定


[Add New Webhook]ボタンを押します。
(下にAdd to Slackがあるので、通知だけが目的ならこれが簡単そう)


URLを入力します。
これはHttps限定かはちょっとわかりませんが、駄目な場合は Let's Encrypt とか使えばいけるのかな?
Secretが必要な場合は入力します。
私は、プロジェクト名をSHA256で変換して入力しておきました。


追加されました。

実装

とりあえず、どんなデータがどこから来るのかを調べる。
適当にPHPで、ログ用なので1行になるように改行を消した。

$message = "";
foreach (getallheaders() as $name => $value) {
    $message .= $name ." => ".$value.", ";
}
$message .= "POST => ".str_replace(array("\r", "\n"), '',print_r($_POST,true)).", ";
$message .= "GET => ".str_replace(array("\r", "\n"), '',print_r($_GET,true)).", ";
$message .= "input => ".file_get_contents('php://input').", ";
file_put_contents("log.txt", date("[Y-m-d H:i:s]")." ".$_SERVER['REMOTE_ADDR'].": ".$message."\n", FILE_APPEND|LOCK_EX);

テスト

[Ping URL]というボタンがあるので押してみると、こんなログがlog.txtに出る。

[2016-06-10 00:00:00] 00.00.00.00: 
X-UnityCloudBuild-HookId => 000, 
X-UnityCloudBuild-Event => Ping, 
X-UnityCloudBuild-DeliveryId => 00000000-0000-0000-0000-000000000000, 
content-type => application/json, 
X-UnityCloudBuild-Signature => 0000000000000000000000000000000000000000000000000000000000000000, 
host => (ドメイン), 
content-length => 000, 
Connection => keep-alive, 
POST => Array(), 
GET => Array(), 
input => {"hookId":000}

大丈夫そうなので、ビルドを開始してみます。

ビルド

開始ボタンを押したときに、以下のものが通知されました。
(input内のjsonを整形)

[2016-06-10 00:00:00] 00.00.00.00: 
X-UnityCloudBuild-HookId => 000, 
X-UnityCloudBuild-Event => ProjectBuildQueued, 
X-UnityCloudBuild-DeliveryId => 00000000-0000-0000-0000-000000000000, 
content-type => application/json, 
X-UnityCloudBuild-Signature => 0000000000000000000000000000000000000000000000000000000000000000, 
host => (ドメイン), 
content-length => 000, 
Connection => keep-alive, 
POST => Array(), 
GET => Array(), 
input => (下に)
input内Json
{
    "projectName":"<projectName>", 
    "buildTargetName":"<buildTargetName>", 
    "projectGuid":"00000000-0000-0000-0000-000000000000", 
    "orgForeignKey":"000000", 
    "buildNumber":0, 
    "buildStatus":"queued", 
    "startedBy":"<username> <mail address>", 
    "platform":"<platform>", 
    "links":{
        "api_self":{
            "method":"get", 
            "href":"/api/orgs/<username>/projects/<projectName>/buildtargets/<buildTargetName>/builds/0"
        }, 
        "dashboard_url":{
            "method":"get", 
            "href":"https://build.cloud.unity3d.com"
        }, 
        "dashboard_project":{
            "method":"get", 
            "href":"/orgs/<username>/projects/<projectName>"
        }, 
        "dashboard_summary":{
            "method":"get", 
            "href":"/orgs/<username>/projects/<projectName>/buildtargets/<buildTargetName>/builds/0/summary"
        }, 
        "dashboard_log":{
            "method":"get", 
            "href":"/orgs/<username>/projects/<projectName>/buildtargets/<buildTargetName>/builds/0/log"
        }
    }
}

ビルドが開始したときには、上記とほぼ同じで、
"buildStatus":"queued",がないものが通知されました。

ビルドが終了したときには、以下のものが通知されました。
(input内のjsonを整形)

[2016-06-10 00:00:00] 00.00.00.00: 
X-UnityCloudBuild-HookId => 000, 
X-UnityCloudBuild-Event => ProjectBuildSuccess, 
X-UnityCloudBuild-DeliveryId => 00000000-0000-0000-0000-000000000000, 
content-type => application/json, 
X-UnityCloudBuild-Signature => 0000000000000000000000000000000000000000000000000000000000000000, 
host => (ドメイン), 
content-length => 000, 
Connection => keep-alive, 
POST => Array(), 
GET => Array(), 
input => (下に)
input内Json
 {
    "projectName":"<projectName>", 
    "buildTargetName":"<buildTargetName>", 
    "projectGuid":"00000000-0000-0000-0000-000000000000", 
    "orgForeignKey":"000000", 
    "buildNumber":0, 
    "buildStatus":"success", 
    "lastBuiltRevision":"0000000000000000000000000000000000000000", 
    "startedBy":"<username> <mail address>", 
    "platform":"<platform>", 
    "links":{
        "api_self":{
            "method":"get", 
            "href":"/api/orgs/<username>/projects/<projectName>/buildtargets/<platform>/builds/0"
        }, 
        "dashboard_url":{
            "method":"get", 
            "href":"https://build.cloud.unity3d.com"
        }, 
        "dashboard_project":{
            "method":"get", 
            "href":"/orgs/<username>/projects/<projectName>"
        }, 
        "dashboard_summary":{
            "method":"get", 
            "href":"/orgs/<username>/projects/<projectName>/buildtargets/<platform>/builds/0/summary"
        }, 
        "dashboard_log":{
            "method":"get", 
            "href":"/orgs/<username>/projects/<projectName>/buildtargets/<platform>/builds/0/log"
        }
    }
}

最後に

UnityCloudBuildの通知が楽になっていて大変いいですね!

おまけ

Unity Online Servicesでプロジェクトは相変わらず消せないようですが、
Archiveが追加され一覧から消せるようになっていました。
o1.png

6
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
5