348.md 2.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
# Project Aliases API

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

*   [List all project aliases](#list-all-project-aliases)
*   [Get project alias’ details](#get-project-alias-details)
*   [Create a project alias](#create-a-project-alias)
*   [Delete a project alias](#delete-a-project-alias)

# Project Aliases API[](#project-aliases-api-premium-only "Permalink")

[Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/3264) in [GitLab Premium](https://about.gitlab.com/pricing/) 12.1.

所有方法都需要管理员授权.

## List all project aliases[](#list-all-project-aliases "Permalink")

获取所有项目别名的列表:

```
GET /project_aliases 
```

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

响应示例:

```
[  {  "id":  1,  "project_id":  1,  "name":  "gitlab-foss"  },  {  "id":  2,  "project_id":  2,  "name":  "gitlab"  }  ] 
```

## Get project alias’ details[](#get-project-alias-details "Permalink")

获取项目别名的详细信息:

```
GET /project_aliases/:name 
```

| Attribute | Type | Required | Description |
| --- | --- | --- | --- |
| `name` | string | yes | 别名的名称 |

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

响应示例:

```
{  "id":  1,  "project_id":  1,  "name":  "gitlab"  } 
```

## Create a project alias[](#create-a-project-alias "Permalink")

为项目添加新的别名. 成功时回应 201,当验证错误时回应 400(例如别名已经存在):

```
POST /project_aliases 
```

| Attribute | Type | Required | Description |
| --- | --- | --- | --- |
| `project_id` | integer/string | yes | 项目的 ID 或路径. |
| `name` | string | yes | 别名的名称. 必须是唯一的. |

```
curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/project_aliases" --form "project_id=1" --form "name=gitlab" 
```

or

```
curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/project_aliases" --form "project_id=gitlab-org/gitlab" --form "name=gitlab" 
```

响应示例:

```
{  "id":  1,  "project_id":  1,  "name":  "gitlab"  } 
```

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

删除项目别名. 存在项目别名时以 204 响应,如果不存在则以 404 响应:

```
DELETE /project_aliases/:name 
```

| Attribute | Type | Required | Description |
| --- | --- | --- | --- |
| `name` | string | yes | 别名的名称 |

```
curl --request DELETE --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/project_aliases/gitlab" 
```