Red Hat Training

A Red Hat training course is available for OpenShift Container Platform

8.7.2.3. Bitbucket Webhook

当存储库更新时,Bitbucket Webhook 处理 Bitbucket 发出的调用。与前面的触发器类似,您必须指定一个 secret。以下示例是 BuildConfig 中的触发器定义 YAML:

type: "Bitbucket"
bitbucket:
  secretReference:
    name: "mysecret"

oc describe 命令将有效负载 URL 返回为 Bitbucket Webhook URL(请参阅显示 Webhook URL),其结构如下:

https://<openshift_api_host:port>/oapi/v1/namespaces/<namespace>/buildconfigs/<name>/webhooks/<secret>/bitbucket

配置 Bitbucket Webhook:

  1. 描述构建配置以获取 Webhook URL:

    $ oc describe bc <name>
  2. 复制 Webhook URL,将 <secret> 替换为您的 secret 值。
  3. 按照 Bitbucket 设置说明,将 Webhook URL 粘贴到 Bitbucket 存储库设置中。

根据包含有效 JSON 有效负载的文件,如 payload.json,您可以通过 curl 手动触发 Webhook:

$ curl -H "X-Event-Key: repo:push" -H "Content-Type: application/json" -k -X POST --data-binary @payload.json https://<openshift_api_host:port>/oapi/v1/namespaces/<namespace>/buildconfigs/<name>/webhooks/<secret>/bitbucket

只有在 API 服务器没有适当签名的证书时,才需要 -k 参数。