Webhook
目錄
您可以使用 Webhook 在響應倉庫中的推送事件時在另一個服務中觸發操作。Webhook 是傳送到您在 Docker Hub 中定義的 URL 的 POST 請求。
建立 Webhook
要建立 Webhook
- 在您選擇的倉庫中,選擇**Webhook**選項卡。
- 為 Webhook 提供一個名稱。
- 提供一個目標 Webhook URL。這是傳遞 Webhook POST 請求的位置。
- 選擇**建立**。
檢視 Webhook 傳遞歷史記錄
要檢視 Webhook 的歷史記錄
- 將滑鼠懸停在**當前 Webhook 部分**下的 Webhook 上。
- 選擇**選單選項**圖示。
- 選擇**檢視歷史記錄**。
然後,您可以檢視傳遞歷史記錄,以及是否成功傳遞 POST 請求。
Webhook 負載示例
Webhook 負載具有以下 JSON 格式
{
"callback_url": "https://registry.hub.docker.com/u/svendowideit/testhook/hook/2141b5bi5i5b02bec211i4eeih0242eg11000a/",
"push_data": {
"pushed_at": 1417566161,
"pusher": "trustedbuilder",
"tag": "latest"
},
"repository": {
"comment_count": 0,
"date_created": 1417494799,
"description": "",
"dockerfile": "#\n# BUILD\u0009\u0009docker build -t svendowideit/apt-cacher .\n# RUN\u0009\u0009docker run -d -p 3142:3142 -name apt-cacher-run apt-cacher\n#\n# and then you can run containers with:\n# \u0009\u0009docker run -t -i -rm -e http_proxy http://192.168.1.2:3142/ debian bash\n#\nFROM\u0009\u0009ubuntu\n\n\nVOLUME\u0009\u0009[/var/cache/apt-cacher-ng]\nRUN\u0009\u0009apt-get update ; apt-get install -yq apt-cacher-ng\n\nEXPOSE \u0009\u00093142\nCMD\u0009\u0009chmod 777 /var/cache/apt-cacher-ng ; /etc/init.d/apt-cacher-ng start ; tail -f /var/log/apt-cacher-ng/*\n",
"full_description": "Docker Hub based automated build from a GitHub repo",
"is_official": false,
"is_private": true,
"is_trusted": true,
"name": "testhook",
"namespace": "svendowideit",
"owner": "svendowideit",
"repo_name": "svendowideit/testhook",
"repo_url": "https://registry.hub.docker.com/u/svendowideit/testhook/",
"star_count": 0,
"status": "Active"
}
}
驗證 Webhook 回撥
要驗證 Webhook 鏈中的回撥,您需要
- 檢索請求的 JSON 負載中的
callback_url
值。 - 向此 URL 傳送包含有效 JSON 主體的 POST 請求。
注意
只有在最後一個回撥得到驗證後,鏈請求才被視為完成。
回撥 JSON 資料
以下引數在回撥資料中被識別
state
(必需):接受的值是success
、failure
和error
。如果狀態不是success
,則 Webhook 鏈將中斷。description
:一個字串,包含在 Docker Hub 上可用的其他資訊。最大 255 個字元。context
:一個字串,包含操作的上下文。可以從 Docker Hub 中檢索。最大 100 個字元。target_url
:可以找到操作結果的 URL。可以在 Docker Hub 上檢索。
以下是一個回撥負載示例
{
"state": "success",
"description": "387 tests PASSED",
"context": "Continuous integration by Acme CI",
"target_url": "https://ci.acme.com/results/afd339c1c3d27"
}