流水线计划 API
- Tier: 基础版, 专业版, 旗舰版
- Offering: JihuLab.com, 私有化部署
你可以阅读更多关于流水线调度的信息。
获取所有流水线调度
获取一个项目的流水线调度列表。
plaintextGET /projects/:id/pipeline_schedules
| Attribute | Type | Required | Description |
|---|---|---|---|
| id | integer/string | Yes | 项目的 ID 或URL 编码路径 |
| scope | string | No | 流水线调度的范围,必须是其中之一:active, inactive |
shellcurl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/29/pipeline_schedules"
json1[ 2 { 3 "id": 13, 4 "description": "Test schedule pipeline", 5 "ref": "refs/heads/main", 6 "cron": "* * * * *", 7 "cron_timezone": "Asia/Tokyo", 8 "next_run_at": "2017-05-19T13:41:00.000Z", 9 "active": true, 10 "created_at": "2017-05-19T13:31:08.849Z", 11 "updated_at": "2017-05-19T13:40:17.727Z", 12 "owner": { 13 "name": "Administrator", 14 "username": "root", 15 "id": 1, 16 "state": "active", 17 "avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon", 18 "web_url": "https://gitlab.example.com/root" 19 } 20 } 21]
获取单个流水线调度
获取一个项目的流水线调度。
plaintextGET /projects/:id/pipeline_schedules/:pipeline_schedule_id
| Attribute | Type | Required | Description |
|---|---|---|---|
| id | integer/string | Yes | 项目的 ID 或URL 编码路径 |
| pipeline_schedule_id | integer | Yes | 流水线调度 ID |
shellcurl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/29/pipeline_schedules/13"
json1{ 2 "id": 13, 3 "description": "Test schedule pipeline", 4 "ref": "refs/heads/main", 5 "cron": "* * * * *", 6 "cron_timezone": "Asia/Tokyo", 7 "next_run_at": "2017-05-19T13:41:00.000Z", 8 "active": true, 9 "created_at": "2017-05-19T13:31:08.849Z", 10 "updated_at": "2017-05-19T13:40:17.727Z", 11 "last_pipeline": { 12 "id": 332, 13 "sha": "0e788619d0b5ec17388dffb973ecd505946156db", 14 "ref": "refs/heads/main", 15 "status": "pending" 16 }, 17 "owner": { 18 "name": "Administrator", 19 "username": "root", 20 "id": 1, 21 "state": "active", 22 "avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon", 23 "web_url": "https://gitlab.example.com/root" 24 }, 25 "variables": [ 26 { 27 "key": "TEST_VARIABLE_1", 28 "variable_type": "env_var", 29 "value": "TEST_1", 30 "raw": false 31 } 32 ] 33}
获取由流水线调度触发的所有流水线
获取项目中由流水线调度触发的所有流水线。
plaintextGET /projects/:id/pipeline_schedules/:pipeline_schedule_id/pipelines
支持的属性:
| Attribute | Type | Required | Description |
|---|---|---|---|
| id | integer/string | Yes | 项目的 ID 或URL 编码路径 |
| pipeline_schedule_id | integer | Yes | 流水线调度 ID |
示例请求:
shellcurl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/29/pipeline_schedules/13/pipelines"
示例响应:
json1[ 2 { 3 "id": 47, 4 "iid": 12, 5 "project_id": 29, 6 "status": "pending", 7 "source": "scheduled", 8 "ref": "new-pipeline", 9 "sha": "a91957a858320c0e17f3a0eca7cfacbff50ea29a", 10 "web_url": "https://example.com/foo/bar/pipelines/47", 11 "created_at": "2016-08-11T11:28:34.085Z", 12 "updated_at": "2016-08-11T11:32:35.169Z" 13 }, 14 { 15 "id": 48, 16 "iid": 13, 17 "project_id": 29, 18 "status": "pending", 19 "source": "scheduled", 20 "ref": "new-pipeline", 21 "sha": "eb94b618fb5865b26e80fdd8ae531b7a63ad851a", 22 "web_url": "https://example.com/foo/bar/pipelines/48", 23 "created_at": "2016-08-12T10:06:04.561Z", 24 "updated_at": "2016-08-12T10:09:56.223Z" 25 } 26]
创建新的流水线调度
创建一个项目的新流水线调度。
plaintextPOST /projects/:id/pipeline_schedules
| Attribute | Type | Required | Description |
|---|---|---|---|
| cron | string | Yes | cron 调度,例如:0 1 * * *。 |
| description | string | Yes | 流水线调度的描述。 |
| id | integer/string | Yes | 项目的 ID 或URL 编码路径 |
| ref | string | Yes | 被触发的分支或标签名称。短版本(例如 main)和完整版本(例如 refs/heads/main 或 refs/tags/main)都可以接受。如果提供了短版本,它会自动扩展为完整版本,但如果 ref 是模糊的,则会被拒绝。 |
| active | boolean | No | 流水线调度的激活状态。如果设置为 false,流水线调度最初是未激活的(默认:true)。 |
| cron_timezone | string | No | ActiveSupport::TimeZone 支持的时区,例如:Pacific Time (US & Canada)(默认:UTC)。 |
shellcurl --request POST --header "PRIVATE-TOKEN: <your_access_token>" \ --form description="Build packages" --form ref="main" --form cron="0 1 * * 5" --form cron_timezone="UTC" \ --form active="true" "https://gitlab.example.com/api/v4/projects/29/pipeline_schedules"
json1{ 2 "id": 14, 3 "description": "Build packages", 4 "ref": "refs/heads/main", 5 "cron": "0 1 * * 5", 6 "cron_timezone": "UTC", 7 "next_run_at": "2017-05-26T01:00:00.000Z", 8 "active": true, 9 "created_at": "2017-05-19T13:43:08.169Z", 10 "updated_at": "2017-05-19T13:43:08.169Z", 11 "last_pipeline": null, 12 "owner": { 13 "name": "Administrator", 14 "username": "root", 15 "id": 1, 16 "state": "active", 17 "avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon", 18 "web_url": "https://gitlab.example.com/root" 19 } 20}
编辑流水线调度
更新项目的流水线调度。更新完成后,它会自动重新调度。
plaintextPUT /projects/:id/pipeline_schedules/:pipeline_schedule_id
| Attribute | Type | Required | Description |
|---|---|---|---|
| id | integer/string | Yes | 项目的 ID 或URL 编码路径 |
| pipeline_schedule_id | integer | Yes | 流水线调度 ID |
| active | boolean | No | 流水线调度的激活状态。如果设置为 false,流水线调度最初是未激活的。 |
| cron_timezone | string | No | ActiveSupport::TimeZone 支持的时区(例如 Pacific Time (US & Canada)),或 TZInfo::Timezone(例如 America/Los_Angeles)。 |
| cron | string | No | cron 调度,例如:0 1 * * *。 |
| description | string | No | 流水线调度的描述。 |
| ref | string | No | 被触发的分支或标签名称。短版本(例如 main)和完整版本(例如 refs/heads/main 或 refs/tags/main)都可以接受。如果提供了短版本,它会自动扩展为完整版本,但如果 ref 是模糊的,则会被拒绝。 |
shellcurl --request PUT --header "PRIVATE-TOKEN: <your_access_token>" \ --form cron="0 2 * * *" "https://gitlab.example.com/api/v4/projects/29/pipeline_schedules/13"
json1{ 2 "id": 13, 3 "description": "Test schedule pipeline", 4 "ref": "refs/heads/main", 5 "cron": "0 2 * * *", 6 "cron_timezone": "Asia/Tokyo", 7 "next_run_at": "2017-05-19T17:00:00.000Z", 8 "active": true, 9 "created_at": "2017-05-19T13:31:08.849Z", 10 "updated_at": "2017-05-19T13:44:16.135Z", 11 "last_pipeline": { 12 "id": 332, 13 "sha": "0e788619d0b5ec17388dffb973ecd505946156db", 14 "ref": "refs/heads/main", 15 "status": "pending" 16 }, 17 "owner": { 18 "name": "Administrator", 19 "username": "root", 20 "id": 1, 21 "state": "active", 22 "avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon", 23 "web_url": "https://gitlab.example.com/root" 24 } 25}
获取流水线调度的所有权
更新项目的流水线调度的所有者。
plaintextPOST /projects/:id/pipeline_schedules/:pipeline_schedule_id/take_ownership
| Attribute | Type | Required | Description |
|---|---|---|---|
| id | integer/string | Yes | 项目的 ID 或URL 编码路径 |
| pipeline_schedule_id | integer | Yes | 流水线调度 ID |
shellcurl --request POST --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/29/pipeline_schedules/13/take_ownership"
json1{ 2 "id": 13, 3 "description": "Test schedule pipeline", 4 "ref": "refs/heads/main", 5 "cron": "0 2 * * *", 6 "cron_timezone": "Asia/Tokyo", 7 "next_run_at": "2017-05-19T17:00:00.000Z", 8 "active": true, 9 "created_at": "2017-05-19T13:31:08.849Z", 10 "updated_at": "2017-05-19T13:46:37.468Z", 11 "last_pipeline": { 12 "id": 332, 13 "sha": "0e788619d0b5ec17388dffb973ecd505946156db", 14 "ref": "refs/heads/main", 15 "status": "pending" 16 }, 17 "owner": { 18 "name": "shinya", 19 "username": "maeda", 20 "id": 50, 21 "state": "active", 22 "avatar_url": "http://www.gravatar.com/avatar/8ca0a796a679c292e3a11da50f99e801?s=80&d=identicon", 23 "web_url": "https://gitlab.example.com/maeda" 24 } 25}
删除流水线调度
删除项目的流水线调度。
plaintextDELETE /projects/:id/pipeline_schedules/:pipeline_schedule_id
| Attribute | Type | Required | Description |
|---|---|---|---|
| id | integer/string | Yes | 项目的 ID 或URL 编码路径 |
| pipeline_schedule_id | integer | Yes | 流水线调度 ID |
shellcurl --request DELETE --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/29/pipeline_schedules/13"
json1{ 2 "id": 13, 3 "description": "Test schedule pipeline", 4 "ref": "refs/heads/main", 5 "cron": "0 2 * * *", 6 "cron_timezone": "Asia/Tokyo", 7 "next_run_at": "2017-05-19T17:00:00.000Z", 8 "active": true, 9 "created_at": "2017-05-19T13:31:08.849Z", 10 "updated_at": "2017-05-19T13:46:37.468Z", 11 "last_pipeline": { 12 "id": 332, 13 "sha": "0e788619d0b5ec17388dffb973ecd505946156db", 14 "ref": "refs/heads/main", 15 "status": "pending" 16 }, 17 "owner": { 18 "name": "shinya", 19 "username": "maeda", 20 "id": 50, 21 "state": "active", 22 "avatar_url": "http://www.gravatar.com/avatar/8ca0a796a679c292e3a11da50f99e801?s=80&d=identicon", 23 "web_url": "https://gitlab.example.com/maeda" 24 } 25}
立即运行已调度的流水线
触发一个新的已调度流水线,该流水线立即运行。此流水线的下一次调度运行不受影响。
plaintextPOST /projects/:id/pipeline_schedules/:pipeline_schedule_id/play
| Attribute | Type | Required | Description |
|---|---|---|---|
| id | integer/string | Yes | 项目的 ID 或URL 编码路径 |
| pipeline_schedule_id | integer | Yes | 流水线调度 ID |
示例请求:
shellcurl --request POST --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/42/pipeline_schedules/1/play"
示例响应:
json{ "message": "201 Created" }
流水线调度变量
创建新的流水线调度变量
创建一个流水线调度的新变量。
plaintextPOST /projects/:id/pipeline_schedules/:pipeline_schedule_id/variables
| Attribute | Type | Required | Description |
|---|---|---|---|
| id | integer/string | Yes | 项目的 ID 或URL 编码路径 |
| key | string | Yes | 变量的 key;不得超过 255 个字符;仅允许 A-Z,a-z,0-9 和 _ |
| pipeline_schedule_id | integer | Yes | 流水线调度 ID |
| value | string | Yes | 变量的 value |
| variable_type | string | No | 变量的类型。可用类型有:env_var(默认)和 file |
shellcurl --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"
json{ "key": "NEW_VARIABLE", "variable_type": "env_var", "value": "new value" }
编辑流水线调度变量
更新流水线调度的变量。
plaintextPUT /projects/:id/pipeline_schedules/:pipeline_schedule_id/variables/:key
| Attribute | Type | Required | Description |
|---|---|---|---|
| id | integer/string | Yes | 项目的 ID 或URL 编码路径 |
| key | string | Yes | 变量的 key |
| pipeline_schedule_id | integer | Yes | 流水线调度 ID |
| value | string | Yes | 变量的 value |
| variable_type | string | No | 变量的类型。可用类型有:env_var(默认)和 file |
shellcurl --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"
json{ "key": "NEW_VARIABLE", "value": "updated value", "variable_type": "env_var" }
删除流水线调度变量
删除流水线调度的变量。
plaintextDELETE /projects/:id/pipeline_schedules/:pipeline_schedule_id/variables/:key
| Attribute | Type | Required | Description |
|---|---|---|---|
| id | integer/string | Yes | 项目的 ID 或URL 编码路径 |
| key | string | Yes | 变量的 key |
| pipeline_schedule_id | integer | Yes | 流水线调度 ID |
shellcurl --request DELETE --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/29/pipeline_schedules/13/variables/NEW_VARIABLE"
json{ "key": "NEW_VARIABLE", "value": "updated value" }