Packages API

原文:https://docs.gitlab.com/ee/api/packages.html

Packages API

这是GitLab 软件包的 API 文档.

List packages

Within a project

在 GitLab 11.8 中引入 .

获取项目包列表. 结果中包括所有包装类型. 在未经身份验证的情况下访问时,仅返回公共项目的软件包.

  1. GET /projects/:id/packages
Attribute Type Required Description
id integer/string yes 项目的 ID 或URL 编码的路径
order_by string no 用作订单的字段. created_at (默认), nameversiontype .
sort string no 顺序的方向, asc (默认)或desc (降序).
package_type string no 按类型过滤返回的软件包. conanmavennpmpypicomposernuget . ( 在 GitLab 12.9 中引入
package_name string no 按名称用模糊搜索过滤项目包. ( 在 GitLab 12.9 中引入
  1. curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/:id/packages"

响应示例:

  1. [ { "id": 1, "name": "com/mycompany/my-app", "version": "1.0-SNAPSHOT", "package_type": "maven", "created_at": "2019-11-27T03:37:38.711Z" }, { "id": 2, "name": "@foo/bar", "version": "1.0.3", "package_type": "npm", "created_at": "2019-11-27T03:37:38.711Z" } ]

默认情况下,由于 API 是分页的 ,因此GET请求将返回 20 个结果.

Within a group

在 GitLab 12.5 中引入 .

获取组级别的项目包列表. 在未经身份验证的情况下访问时,仅返回公共项目的软件包.

  1. GET /groups/:id/packages
Attribute Type Required Description
id integer/string yes 群组的 ID 或URL 编码路径 .
exclude_subgroups boolean false 如果参数包含为 true,则不列出子组中项目的软件包. 默认值为false .
order_by string no 用作订单的字段. created_at (默认), nameversiontypeproject_path .
sort string no 顺序的方向, asc (默认)或desc (降序).
package_type string no 按类型过滤返回的软件包. conanmavennpmpypicomposernuget . ( 在 GitLab 12.9 中引入
package_name string no 按名称用模糊搜索过滤项目包. ( 在 GitLab 13.0 中引入
  1. curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/groups/:id/packages?exclude_subgroups=true"

弃用:>build_info在响应属性赞成不赞成pipeline . >引入了GitLab 12.10 .

响应示例:

  1. [ { "id": 1, "name": "com/mycompany/my-app", "version": "1.0-SNAPSHOT", "package_type": "maven", "_links": { "web_path": "/namespace1/project1/-/packages/1", "delete_api_path": "/namespace1/project1/-/packages/1" }, "created_at": "2019-11-27T03:37:38.711Z", "pipeline": { "id": 123, "status": "pending", "ref": "new-pipeline", "sha": "a91957a858320c0e17f3a0eca7cfacbff50ea29a", "web_url": "https://example.com/foo/bar/pipelines/47", "created_at": "2016-08-11T11:28:34.085Z", "updated_at": "2016-08-11T11:32:35.169Z", "user": { "name": "Administrator", "avatar_url": "https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon" } } }, { "id": 2, "name": "@foo/bar", "version": "1.0.3", "package_type": "npm", "_links": { "web_path": "/namespace1/project1/-/packages/1", "delete_api_path": "/namespace1/project1/-/packages/1" }, "created_at": "2019-11-27T03:37:38.711Z", "pipeline": { "id": 123, "status": "pending", "ref": "new-pipeline", "sha": "a91957a858320c0e17f3a0eca7cfacbff50ea29a", "web_url": "https://example.com/foo/bar/pipelines/47", "created_at": "2016-08-11T11:28:34.085Z", "updated_at": "2016-08-11T11:32:35.169Z", "user": { "name": "Administrator", "avatar_url": "https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon" } } } ]

默认情况下,由于 API 是分页的 ,因此GET请求将返回 20 个结果.

_links对象包含以下属性:

  • web_path :您可以在 GitLab 中访问并查看软件包详细信息的路径.
  • delete_api_path :删除程序包的 API 路径. 仅在请求用户有权执行此操作时可用.

Get a project package

在 GitLab 11.9 中引入 .

获得一个项目包.

  1. GET /projects/:id/packages/:package_id
Attribute Type Required Description
id integer/string yes 项目的 ID 或URL 编码路径 .
package_id integer yes 包裹的 ID.
  1. curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/:id/packages/:package_id"

弃用:>build_info在响应属性赞成不赞成pipeline . >引入了GitLab 12.10 .

Example response:

  1. { "id": 1, "name": "com/mycompany/my-app", "version": "1.0-SNAPSHOT", "package_type": "maven", "_links": { "web_path": "/namespace1/project1/-/packages/1", "delete_api_path": "/namespace1/project1/-/packages/1" }, "created_at": "2019-11-27T03:37:38.711Z", "pipeline": { "id": 123, "status": "pending", "ref": "new-pipeline", "sha": "a91957a858320c0e17f3a0eca7cfacbff50ea29a", "web_url": "https://example.com/foo/bar/pipelines/47", "created_at": "2016-08-11T11:28:34.085Z", "updated_at": "2016-08-11T11:32:35.169Z", "user": { "name": "Administrator", "avatar_url": "https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon" } }, "versions": [ { "id":2, "version":"2.0-SNAPSHOT", "created_at":"2020-04-28T04:42:11.573Z", "pipeline": { "id": 234, "status": "pending", "ref": "new-pipeline", "sha": "a91957a858320c0e17f3a0eca7cfacbff50ea29a", "web_url": "https://example.com/foo/bar/pipelines/58", "created_at": "2016-08-11T11:28:34.085Z", "updated_at": "2016-08-11T11:32:35.169Z", "user": { "name": "Administrator", "avatar_url": "https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon" } } } ] }

_links对象包含以下属性:

  • web_path :您可以在 GitLab 中访问并查看软件包详细信息的路径.
  • delete_api_path :删除程序包的 API 路径. 仅在请求用户有权执行此操作时可用.

List package files

在 GitLab 11.8 中引入 .

获取单个软件包的软件包文件列表.

  1. GET /projects/:id/packages/:package_id/package_files
Attribute Type Required Description
id integer/string yes 项目的 ID 或URL 编码的路径
package_id integer yes 包裹的 ID.
  1. curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/1/packages/4/package_files"

响应示例:

  1. [ { "id": 25, "package_id": 4, "created_at": "2018-11-07T15:25:52.199Z", "file_name": "my-app-1.5-20181107.152550-1.jar", "size": 2421, "file_md5": "58e6a45a629910c6ff99145a688971ac", "file_sha1": "ebd193463d3915d7e22219f52740056dfd26cbfe" }, { "id": 26, "package_id": 4, "created_at": "2018-11-07T15:25:56.776Z", "file_name": "my-app-1.5-20181107.152550-1.pom", "size": 1122, "file_md5": "d90f11d851e17c5513586b4a7e98f1b2", "file_sha1": "9608d068fe88aff85781811a42f32d97feb440b5" }, { "id": 27, "package_id": 4, "created_at": "2018-11-07T15:26:00.556Z", "file_name": "maven-metadata.xml", "size": 767, "file_md5": "6dfd0cce1203145a927fef5e3a1c650c", "file_sha1": "d25932de56052d320a8ac156f745ece73f6a8cd2" } ]

默认情况下,由于 API 是分页的 ,因此GET请求将返回 20 个结果.

Delete a project package

在 GitLab 11.9 中引入 .

删除项目包.

  1. DELETE /projects/:id/packages/:package_id
Attribute Type Required Description
id integer/string yes 项目的 ID 或URL 编码的路径
package_id integer yes 包裹的 ID.
  1. curl --request DELETE --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/:id/packages/:package_id"

可以返回以下状态码:

  • 204 No Content ,如果软件包已成功删除.
  • 404 Not Found ,如果404 Not Found包.