Help us learn about your current experience with the documentation. Take the survey.

发布链接 API

  • 版本:Free, Premium, Ultimate
  • 提供:GitLab.com, GitLab Self-Managed, GitLab Dedicated

使用此 API 与 发布 的链接进行交互。

GitLab 支持以下协议的资源链接:

  • http
  • https
  • ftp

要与项目发布直接交互,请参阅 项目发布 API

列出发布的链接

从发布中获取资源链接。

GET /projects/:id/releases/:tag_name/assets/links
属性 类型 必需 描述
id integer/string 项目的 ID 或 URL 编码路径
tag_name string 与发布关联的标签。

示例请求:

curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/24/releases/v0.1/assets/links"

示例响应:

[
   {
      "id":2,
      "name":"awesome-v0.2.msi",
      "url":"http://192.168.10.15:3000/msi",
      "link_type":"other"
   },
   {
      "id":1,
      "name":"awesome-v0.2.dmg",
      "url":"http://192.168.10.15:3000",
      "link_type":"other"
   }
]

获取发布链接

从发布中获取资源链接。

GET /projects/:id/releases/:tag_name/assets/links/:link_id
属性 类型 必需 描述
id integer/string 项目的 ID 或 URL 编码路径
tag_name string 与发布关联的标签。
link_id integer 链接的 ID。

示例请求:

curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/24/releases/v0.1/assets/links/1"

示例响应:

{
   "id":1,
   "name":"awesome-v0.2.dmg",
   "url":"http://192.168.10.15:3000",
   "link_type":"other"
}

创建发布链接

从发布中创建资源链接。

POST /projects/:id/releases/:tag_name/assets/links
属性 类型 必需 描述
id integer/string 项目的 ID 或 URL 编码路径
tag_name string 与发布关联的标签。
name string 链接的名称。链接名称在发布中必须唯一。
url string 链接的 URL。链接 URL 在发布中必须唯一。
direct_asset_path string 直接资源链接 的可选路径。
link_type string 链接类型:otherrunbookimagepackage。默认为 other

示例请求:

curl --request POST \
    --header "PRIVATE-TOKEN: <your_access_token>" \
    --data name="hellodarwin-amd64" \
    --data url="https://gitlab.example.com/mynamespace/hello/-/jobs/688/artifacts/raw/bin/hello-darwin-amd64" \
    --data direct_asset_path="/bin/hellodarwin-amd64" \
    "https://gitlab.example.com/api/v4/projects/20/releases/v1.7.0/assets/links"

示例响应:

{
   "id":2,
   "name":"hellodarwin-amd64",
   "url":"https://gitlab.example.com/mynamespace/hello/-/jobs/688/artifacts/raw/bin/hello-darwin-amd64",
   "direct_asset_url":"https://gitlab.example.com/mynamespace/hello/-/releases/v1.7.0/downloads/bin/hellodarwin-amd64",
   "link_type":"other"
}

更新发布链接

更新发布中的资源链接。

PUT /projects/:id/releases/:tag_name/assets/links/:link_id
属性 类型 必需 描述
id integer/string 项目的 ID 或 URL 编码路径
tag_name string 与发布关联的标签。
link_id integer 链接的 ID。
name string 链接的名称。
url string 链接的 URL。
direct_asset_path string 直接资源链接 的可选路径。
link_type string 链接类型:otherrunbookimagepackage。默认为 other

您必须指定 nameurl 中的至少一个

示例请求:

curl --request PUT --data name="new name" --data link_type="runbook" \
     --header "PRIVATE-TOKEN: <your_access_token>" \
     "https://gitlab.example.com/api/v4/projects/24/releases/v0.1/assets/links/1"

示例响应:

{
   "id":1,
   "name":"new name",
   "url":"http://192.168.10.15:3000",
   "link_type":"runbook"
}

删除发布链接

删除发布中的资源链接。

DELETE /projects/:id/releases/:tag_name/assets/links/:link_id
属性 类型 必需 描述
id integer/string 项目的 ID 或 URL 编码路径
tag_name string 与发布关联的标签。
link_id integer 链接的 ID。

示例请求:

curl --request DELETE --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/24/releases/v0.1/assets/links/1"

示例响应:

{
   "id":1,
   "name":"new name",
   "url":"http://192.168.10.15:3000",
   "link_type":"other"
}