# Pipeline schedules API

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

*   [Get all pipeline schedules](#get-all-pipeline-schedules)
*   [Get a single pipeline schedule](#get-a-single-pipeline-schedule)
*   [Create a new pipeline schedule](#create-a-new-pipeline-schedule)
*   [Edit a pipeline schedule](#edit-a-pipeline-schedule)
*   [Take ownership of a pipeline schedule](#take-ownership-of-a-pipeline-schedule)
*   [Delete a pipeline schedule](#delete-a-pipeline-schedule)
*   [Run a scheduled pipeline immediately](#run-a-scheduled-pipeline-immediately)
*   [Pipeline schedule variables](#pipeline-schedule-variables)
*   [Create a new pipeline schedule variable](#create-a-new-pipeline-schedule-variable)
*   [Edit a pipeline schedule variable](#edit-a-pipeline-schedule-variable)
*   [Delete a pipeline schedule variable](#delete-a-pipeline-schedule-variable)

# Pipeline schedules API[](#pipeline-schedules-api "Permalink")

您可以阅读有关[管道计划的](../ci/pipelines/schedules.html)更多信息.

## Get all pipeline schedules[](#get-all-pipeline-schedules "Permalink")

获取项目的管道时间表的列表.

```
GET /projects/:id/pipeline_schedules 
```

| Attribute | Type | required | Description |
| --- | --- | --- | --- |
| `id` | integer/string | yes | The ID or [URL-encoded path of the project](README.html#namespaced-path-encoding) owned by the authenticated user |
| `scope` | string | no | 管道计划的范围，其中之一： `active` ， `inactive` |

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

```
[  {  "id":  13,  "description":  "Test schedule pipeline",  "ref":  "master",  "cron":  "* * * * *",  "cron_timezone":  "Asia/Tokyo",  "next_run_at":  "2017-05-19T13:41:00.000Z",  "active":  true,  "created_at":  "2017-05-19T13:31:08.849Z",  "updated_at":  "2017-05-19T13:40:17.727Z",  "owner":  {  "name":  "Administrator",  "username":  "root",  "id":  1,  "state":  "active",  "avatar_url":  "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon",  "web_url":  "https://gitlab.example.com/root"  }  }  ] 
```

## Get a single pipeline schedule[](#get-a-single-pipeline-schedule "Permalink")

获取项目的管道计划.

```
GET /projects/:id/pipeline_schedules/:pipeline_schedule_id 
```

| Attribute | Type | required | Description |
| --- | --- | --- | --- |
| `id` | integer/string | yes | 经过身份验证的用户拥有[的项目](README.html#namespaced-path-encoding)的 ID 或[URL 编码路径](README.html#namespaced-path-encoding) |
| `pipeline_schedule_id` | integer | yes | 管道时间表 ID |

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

```
{  "id":  13,  "description":  "Test schedule pipeline",  "ref":  "master",  "cron":  "* * * * *",  "cron_timezone":  "Asia/Tokyo",  "next_run_at":  "2017-05-19T13:41:00.000Z",  "active":  true,  "created_at":  "2017-05-19T13:31:08.849Z",  "updated_at":  "2017-05-19T13:40:17.727Z",  "last_pipeline":  {  "id":  332,  "sha":  "0e788619d0b5ec17388dffb973ecd505946156db",  "ref":  "master",  "status":  "pending"  },  "owner":  {  "name":  "Administrator",  "username":  "root",  "id":  1,  "state":  "active",  "avatar_url":  "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon",  "web_url":  "https://gitlab.example.com/root"  },  "variables":  [  {  "key":  "TEST_VARIABLE_1",  "variable_type":  "env_var",  "value":  "TEST_1"  }  ]  } 
```

## Create a new pipeline schedule[](#create-a-new-pipeline-schedule "Permalink")

创建一个新的项目管道计划.

```
POST /projects/:id/pipeline_schedules 
```

| Attribute | Type | required | Description |
| --- | --- | --- | --- |
| `id` | integer/string | yes | 经过身份验证的用户拥有[的项目](README.html#namespaced-path-encoding)的 ID 或[URL 编码路径](README.html#namespaced-path-encoding) |
| `description` | string | yes | 管道进度表的描述 |
| `ref` | string | yes | 分支/标签名称将被触发 |
| `cron` | string | yes | cron（例如`0 1 * * *` ）（ [Cron 语法](https://en.wikipedia.org/wiki/Cron) ） |
| `cron_timezone` | string | no | `ActiveSupport::TimeZone`支持的时`ActiveSupport::TimeZone` （例如`Pacific Time (US & Canada)` ）（默认值： `'UTC'` ） |
| `active` | boolean | no | 激活管道计划. 如果设置为 false，则管道调度最初将被停用（默认值： `true` ） |

```
curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" --form description="Build packages" --form ref="master" --form cron="0 1 * * 5" --form cron_timezone="UTC" --form active="true" "https://gitlab.example.com/api/v4/projects/29/pipeline_schedules" 
```

```
{  "id":  14,  "description":  "Build packages",  "ref":  "master",  "cron":  "0 1 * * 5",  "cron_timezone":  "UTC",  "next_run_at":  "2017-05-26T01:00:00.000Z",  "active":  true,  "created_at":  "2017-05-19T13:43:08.169Z",  "updated_at":  "2017-05-19T13:43:08.169Z",  "last_pipeline":  null,  "owner":  {  "name":  "Administrator",  "username":  "root",  "id":  1,  "state":  "active",  "avatar_url":  "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon",  "web_url":  "https://gitlab.example.com/root"  }  } 
```

## Edit a pipeline schedule[](#edit-a-pipeline-schedule "Permalink")

更新项目的管道计划. 更新完成后，将自动重新安排.

```
PUT /projects/:id/pipeline_schedules/:pipeline_schedule_id 
```

| Attribute | Type | required | Description |
| --- | --- | --- | --- |
| `id` | integer/string | yes | 经过身份验证的用户拥有[的项目](README.html#namespaced-path-encoding)的 ID 或[URL 编码路径](README.html#namespaced-path-encoding) |
| `pipeline_schedule_id` | integer | yes | 管道时间表 ID |
| `description` | string | no | 管道进度表的描述 |
| `ref` | string | no | 分支/标签名称将被触发 |
| `cron` | string | no | cron（例如`0 1 * * *` ）（ [Cron 语法](https://en.wikipedia.org/wiki/Cron) ） |
| `cron_timezone` | string | no | `ActiveSupport::TimeZone` （例如`Pacific Time (US & Canada)` ）或`TZInfo::Timezone` （例如`America/Los_Angeles` ）支持的`TZInfo::Timezone` |
| `active` | boolean | no | 激活管道计划. 如果设置为 false，则管道计划将首先停用. |

```
curl --request PUT --header "PRIVATE-TOKEN: <your_access_token>" --form cron="0 2 * * *" "https://gitlab.example.com/api/v4/projects/29/pipeline_schedules/13" 
```

```
{  "id":  13,  "description":  "Test schedule pipeline",  "ref":  "master",  "cron":  "0 2 * * *",  "cron_timezone":  "Asia/Tokyo",  "next_run_at":  "2017-05-19T17:00:00.000Z",  "active":  true,  "created_at":  "2017-05-19T13:31:08.849Z",  "updated_at":  "2017-05-19T13:44:16.135Z",  "last_pipeline":  {  "id":  332,  "sha":  "0e788619d0b5ec17388dffb973ecd505946156db",  "ref":  "master",  "status":  "pending"  },  "owner":  {  "name":  "Administrator",  "username":  "root",  "id":  1,  "state":  "active",  "avatar_url":  "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon",  "web_url":  "https://gitlab.example.com/root"  }  } 
```

## Take ownership of a pipeline schedule[](#take-ownership-of-a-pipeline-schedule "Permalink")

更新项目的管道计划的所有者.

```
POST /projects/:id/pipeline_schedules/:pipeline_schedule_id/take_ownership 
```

| Attribute | Type | required | Description |
| --- | --- | --- | --- |
| `id` | integer/string | yes | 经过身份验证的用户拥有[的项目](README.html#namespaced-path-encoding)的 ID 或[URL 编码路径](README.html#namespaced-path-encoding) |
| `pipeline_schedule_id` | integer | yes | 管道时间表 ID |

```
curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/29/pipeline_schedules/13/take_ownership" 
```

```
{  "id":  13,  "description":  "Test schedule pipeline",  "ref":  "master",  "cron":  "0 2 * * *",  "cron_timezone":  "Asia/Tokyo",  "next_run_at":  "2017-05-19T17:00:00.000Z",  "active":  true,  "created_at":  "2017-05-19T13:31:08.849Z",  "updated_at":  "2017-05-19T13:46:37.468Z",  "last_pipeline":  {  "id":  332,  "sha":  "0e788619d0b5ec17388dffb973ecd505946156db",  "ref":  "master",  "status":  "pending"  },  "owner":  {  "name":  "shinya",  "username":  "maeda",  "id":  50,  "state":  "active",  "avatar_url":  "http://www.gravatar.com/avatar/8ca0a796a679c292e3a11da50f99e801?s=80&d=identicon",  "web_url":  "https://gitlab.example.com/maeda"  }  } 
```

## Delete a pipeline schedule[](#delete-a-pipeline-schedule "Permalink")

删除项目的管道计划.

```
DELETE /projects/:id/pipeline_schedules/:pipeline_schedule_id 
```

| Attribute | Type | required | Description |
| --- | --- | --- | --- |
| `id` | integer/string | yes | 经过身份验证的用户拥有[的项目](README.html#namespaced-path-encoding)的 ID 或[URL 编码路径](README.html#namespaced-path-encoding) |
| `pipeline_schedule_id` | integer | yes | 管道时间表 ID |

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

```
{  "id":  13,  "description":  "Test schedule pipeline",  "ref":  "master",  "cron":  "0 2 * * *",  "cron_timezone":  "Asia/Tokyo",  "next_run_at":  "2017-05-19T17:00:00.000Z",  "active":  true,  "created_at":  "2017-05-19T13:31:08.849Z",  "updated_at":  "2017-05-19T13:46:37.468Z",  "last_pipeline":  {  "id":  332,  "sha":  "0e788619d0b5ec17388dffb973ecd505946156db",  "ref":  "master",  "status":  "pending"  },  "owner":  {  "name":  "shinya",  "username":  "maeda",  "id":  50,  "state":  "active",  "avatar_url":  "http://www.gravatar.com/avatar/8ca0a796a679c292e3a11da50f99e801?s=80&d=identicon",  "web_url":  "https://gitlab.example.com/maeda"  }  } 
```

## Run a scheduled pipeline immediately[](#run-a-scheduled-pipeline-immediately "Permalink")

在 GitLab 12.8 中[引入](https://gitlab.com/gitlab-org/gitlab/-/issues/201786) .

触发一个新的计划管道，该管道将立即运行. 该管道的下一个计划运行不受影响.

```
POST /projects/:id/pipeline_schedules/:pipeline_schedule_id/play 
```

| Attribute | Type | required | Description |
| --- | --- | --- | --- |
| `id` | integer/string | yes | 经过身份验证的用户拥有[的项目](README.html#namespaced-path-encoding)的 ID 或[URL 编码路径](README.html#namespaced-path-encoding) |
| `pipeline_schedule_id` | integer | yes | 管道时间表 ID |

请求示例：

```
curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/42/pipeline_schedules/1/play" 
```

响应示例：

```
{  "message":  "201 Created"  } 
```

## Pipeline schedule variables[](#pipeline-schedule-variables "Permalink")

在 GitLab 10.0 中[引入](https://gitlab.com/gitlab-org/gitlab-foss/-/issues/34518) .

## Create a new pipeline schedule variable[](#create-a-new-pipeline-schedule-variable "Permalink")

创建管道计划的新变量.

```
POST /projects/:id/pipeline_schedules/:pipeline_schedule_id/variables 
```

| Attribute | Type | required | Description |
| --- | --- | --- | --- |
| `id` | integer/string | yes | 经过身份验证的用户拥有[的项目](README.html#namespaced-path-encoding)的 ID 或[URL 编码路径](README.html#namespaced-path-encoding) |
| `pipeline_schedule_id` | integer | yes | 管道时间表 ID |
| `key` | string | yes | 变量的`key` ； 不得超过 255 个字符； 仅允许`AZ` ， `az` ， `0-9`和`_` |
| `value` | string | yes | 变量的`value` |
| `variable_type` | string | no | 变量的类型. 可用类型为： `env_var` （默认）和`file` |

```
curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" --form "key=NEW_VARIABLE" --form "value=new value" "https://gitlab.example.com/api/v4/projects/29/pipeline_schedules/13/variables" 
```

```
{  "key":  "NEW_VARIABLE",  "variable_type":  "env_var",  "value":  "new value"  } 
```

## Edit a pipeline schedule variable[](#edit-a-pipeline-schedule-variable "Permalink")

更新管道计划的变量.

```
PUT /projects/:id/pipeline_schedules/:pipeline_schedule_id/variables/:key 
```

| Attribute | Type | required | Description |
| --- | --- | --- | --- |
| `id` | integer/string | yes | 经过身份验证的用户拥有[的项目](README.html#namespaced-path-encoding)的 ID 或[URL 编码路径](README.html#namespaced-path-encoding) |
| `pipeline_schedule_id` | integer | yes | 管道时间表 ID |
| `key` | string | yes | 变量的`key` |
| `value` | string | yes | 变量的`value` |
| `variable_type` | string | no | 变量的类型. 可用类型为： `env_var` （默认）和`file` |

```
curl --request PUT --header "PRIVATE-TOKEN: <your_access_token>" --form "value=updated value" "https://gitlab.example.com/api/v4/projects/29/pipeline_schedules/13/variables/NEW_VARIABLE" 
```

```
{  "key":  "NEW_VARIABLE",  "value":  "updated value"  "variable_type":  "env_var",  } 
```

## Delete a pipeline schedule variable[](#delete-a-pipeline-schedule-variable "Permalink")

删除管道计划的变量.

```
DELETE /projects/:id/pipeline_schedules/:pipeline_schedule_id/variables/:key 
```

| Attribute | Type | required | Description |
| --- | --- | --- | --- |
| `id` | integer/string | yes | 经过身份验证的用户拥有[的项目](README.html#namespaced-path-encoding)的 ID 或[URL 编码路径](README.html#namespaced-path-encoding) |
| `pipeline_schedule_id` | integer | yes | 管道时间表 ID |
| `key` | string | yes | 变量的`key` |

```
curl --request DELETE --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/29/pipeline_schedules/13/variables/NEW_VARIABLE" 
```

```
{  "key":  "NEW_VARIABLE",  "value":  "updated value"  } 
```