343.md 9.7 KB
Newer Older
Lab机器人's avatar
readme  
Lab机器人 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
# Packages API

> 原文:[https://docs.gitlab.com/ee/api/packages.html](https://docs.gitlab.com/ee/api/packages.html)

*   [List packages](#list-packages)
    *   [Within a project](#within-a-project)
    *   [Within a group](#within-a-group)
*   [Get a project package](#get-a-project-package)
*   [List package files](#list-package-files)
*   [Delete a project package](#delete-a-project-package)

# Packages API[](#packages-api-premium "Permalink")

这是[GitLab 软件包](../administration/packages/index.html)的 API 文档.

## List packages[](#list-packages "Permalink")

### Within a project[](#within-a-project "Permalink")

在 GitLab 11.8 中[引入](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/9259) .

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

```
GET /projects/:id/packages 
```

| Attribute | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | integer/string | yes | 项目的 ID 或[URL 编码的路径](README.html#namespaced-path-encoding) |
| `order_by` | string | no | 用作订单的字段. `created_at` (默认), `name``version``type` . |
| `sort` | string | no | 顺序的方向, `asc` (默认)或`desc` (降序). |
| `package_type` | string | no | 按类型过滤返回的软件包. `conan``maven``npm``pypi``composer``nuget` . ( *在 GitLab 12.9 中引入* ) |
| `package_name` | string | no | 按名称用模糊搜索过滤项目包. ( *在 GitLab 12.9 中引入* ) |

```
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/:id/packages" 
```

响应示例:

```
[  {  "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 是[分页的](README.html#pagination) ,因此`GET`请求将返回 20 个结果.

### Within a group[](#within-a-group "Permalink")

在 GitLab 12.5 中[引入](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/18871) .

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

```
GET /groups/:id/packages 
```

| Attribute | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | integer/string | yes | [群组的](README.html#namespaced-path-encoding) ID 或[URL 编码路径](README.html#namespaced-path-encoding) . |
| `exclude_subgroups` | boolean | false | 如果参数包含为 true,则不列出子组中项目的软件包. 默认值为`false` . |
| `order_by` | string | no | 用作订单的字段. `created_at` (默认), `name``version``type``project_path` . |
| `sort` | string | no | 顺序的方向, `asc` (默认)或`desc` (降序). |
| `package_type` | string | no | 按类型过滤返回的软件包. `conan``maven``npm``pypi``composer``nuget` . ( *在 GitLab 12.9 中引入* ) |
| `package_name` | string | no | 按名称用模糊搜索过滤项目包. ( *在 GitLab 13.0 中[引入](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/30980)* ) |

```
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](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/28040) .

响应示例:

```
[  {  "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 是[分页的](README.html#pagination) ,因此`GET`请求将返回 20 个结果.

`_links`对象包含以下属性:

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

## Get a project package[](#get-a-project-package "Permalink")

在 GitLab 11.9 中[引入](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/9667) .

获得一个项目包.

```
GET /projects/:id/packages/:package_id 
```

| Attribute | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | integer/string | yes | 项目的 ID 或[URL 编码路径](README.html#namespaced-path-encoding) . |
| `package_id` | integer | yes | 包裹的 ID. |

```
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/:id/packages/:package_id" 
```

**弃用:>**`build_info`在响应属性赞成不赞成`pipeline` . >引入了[GitLab 12.10](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/28040) .

Example response:

```
{  "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[](#list-package-files "Permalink")

在 GitLab 11.8 中[引入](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/9305) .

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

```
GET /projects/:id/packages/:package_id/package_files 
```

| Attribute | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | integer/string | yes | 项目的 ID 或[URL 编码的路径](README.html#namespaced-path-encoding) |
| `package_id` | integer | yes | 包裹的 ID. |

```
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/1/packages/4/package_files" 
```

响应示例:

```
[  {  "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 是[分页的](README.html#pagination) ,因此`GET`请求将返回 20 个结果.

## Delete a project package[](#delete-a-project-package "Permalink")

在 GitLab 11.9 中[引入](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/9623) .

删除项目包.

```
DELETE /projects/:id/packages/:package_id 
```

| Attribute | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | integer/string | yes | 项目的 ID 或[URL 编码的路径](README.html#namespaced-path-encoding) |
| `package_id` | integer | yes | 包裹的 ID. |

```
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`包.