# Freeze Periods API

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

*   [Permissions and security](#permissions-and-security)
*   [List Freeze Periods](#list-freeze-periods)
*   [Get a Freeze Period by a `freeze_period_id`](#get-a-freeze-period-by-a-freeze_period_id)
*   [Create a Freeze Period](#create-a-freeze-period)
*   [Update a Freeze Period](#update-a-freeze-period)
*   [Delete a Freeze Period](#delete-a-freeze-period)

# Freeze Periods API[](#freeze-periods-api "Permalink")

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

您可以使用 Freeze Periods API 来操纵 GitLab 的[Freeze Period](../user/project/releases/index.html#prevent-unintentional-releases-by-setting-a-deploy-freeze)条目.

## Permissions and security[](#permissions-and-security "Permalink")

只有具有维护者[权限的](../user/permissions.html)用户才能与 Freeze Period API 端点进行交互.

## List Freeze Periods[](#list-freeze-periods "Permalink")

冻结期间的分页列表，按`created_at`升序排序.

```
GET /projects/:id/freeze_periods 
```

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

请求示例：

```
curl --header "PRIVATE-TOKEN: gVWYVHDRzXiRpN1rUC8T" "https://gitlab.example.com/api/v4/projects/19/freeze_periods" 
```

响应示例：

```
[  {  "id":1,  "freeze_start":"0 23 * * 5",  "freeze_end":"0 8 * * 1",  "cron_timezone":"UTC",  "created_at":"2020-05-15T17:03:35.702Z",  "updated_at":"2020-05-15T17:06:41.566Z"  }  ] 
```

## Get a Freeze Period by a `freeze_period_id`[](#get-a-freeze-period-by-a-freeze_period_id "Permalink")

获取给定的`freeze_period_id`的冻结期.

```
GET /projects/:id/freeze_periods/:freeze_period_id 
```

| Attribute | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | 整数或字符串 | yes | 项目的 ID 或[URL 编码的路径](README.html#namespaced-path-encoding) . |
| `freeze_period_id` | string | yes | 冻结期的数据库 ID. |

请求示例：

```
curl --header "PRIVATE-TOKEN: gVWYVHDRzXiRpN1rUC8T" "https://gitlab.example.com/api/v4/projects/19/freeze_periods/1" 
```

响应示例：

```
{  "id":1,  "freeze_start":"0 23 * * 5",  "freeze_end":"0 8 * * 1",  "cron_timezone":"UTC",  "created_at":"2020-05-15T17:03:35.702Z",  "updated_at":"2020-05-15T17:06:41.566Z"  } 
```

## Create a Freeze Period[](#create-a-freeze-period "Permalink")

创建冻结期.

```
POST /projects/:id/freeze_periods 
```

| Attribute | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | 整数或字符串 | yes | 项目的 ID 或[URL 编码的路径](README.html#namespaced-path-encoding) . |
| `freeze_start` | string | yes | [Cron](https://crontab.guru/)格式的冻结期开始. |
| `freeze_end` | string | yes | [Cron](https://crontab.guru/)格式的冻结期结束. |
| `cron_timezone` | string | no | cron 字段的时区，如果未提供，则默认为 UTC. |

请求示例：

```
curl --header 'Content-Type: application/json' --header "PRIVATE-TOKEN: gVWYVHDRzXiRpN1rUC8T" \
     --data '{ "freeze_start": "0 23 * * 5", "freeze_end": "0 7 * * 1", "cron_timezone": "UTC" }' \
     --request POST https://gitlab.example.com/api/v4/projects/19/freeze_periods 
```

响应示例：

```
{  "id":1,  "freeze_start":"0 23 * * 5",  "freeze_end":"0 7 * * 1",  "cron_timezone":"UTC",  "created_at":"2020-05-15T17:03:35.702Z",  "updated_at":"2020-05-15T17:03:35.702Z"  } 
```

## Update a Freeze Period[](#update-a-freeze-period "Permalink")

为给定的`freeze_period_id`更新冻结期.

```
PUT /projects/:id/freeze_periods/:tag_name 
```

| Attribute | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | 整数或字符串 | yes | 项目的 ID 或[URL 编码的路径](README.html#namespaced-path-encoding) . |
| `freeze_period_id` | 整数或字符串 | yes | 冻结期的数据库 ID. |
| `freeze_start` | string | no | [Cron](https://crontab.guru/)格式的冻结期开始. |
| `freeze_end` | string | no | [Cron](https://crontab.guru/)格式的冻结期结束. |
| `cron_timezone` | string | no | cron 字段的时区. |

请求示例：

```
curl --header 'Content-Type: application/json' --header "PRIVATE-TOKEN: gVWYVHDRzXiRpN1rUC8T" \
     --data '{ "freeze_end": "0 8 * * 1" }' \
     --request PUT https://gitlab.example.com/api/v4/projects/19/freeze_periods/1 
```

响应示例：

```
{  "id":1,  "freeze_start":"0 23 * * 5",  "freeze_end":"0 8 * * 1",  "cron_timezone":"UTC",  "created_at":"2020-05-15T17:03:35.702Z",  "updated_at":"2020-05-15T17:06:41.566Z"  } 
```

## Delete a Freeze Period[](#delete-a-freeze-period "Permalink")

删除给定的`freeze_period_id`的冻结期.

```
DELETE /projects/:id/freeze_periods/:freeze_period_id 
```

| Attribute | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | 整数或字符串 | yes | 项目的 ID 或[URL 编码的路径](README.html#namespaced-path-encoding) . |
| `freeze_period_id` | string | yes | 冻结期的数据库 ID. |

请求示例：

```
curl --request DELETE --header "PRIVATE-TOKEN: gVWYVHDRzXiRpN1rUC8T" "https://gitlab.example.com/api/v4/projects/19/freeze_periods/1" 
```