345.md 13.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 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255
# 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"  } 
```