流水线计划 API

  • Tier: 基础版, 专业版, 旗舰版
  • Offering: JihuLab.com, 私有化部署

你可以阅读更多关于流水线调度的信息。

获取所有流水线调度#

获取一个项目的流水线调度列表。

plaintext
GET /projects/:id/pipeline_schedules
AttributeTypeRequiredDescription
idinteger/stringYes项目的 ID 或URL 编码路径
scopestringNo流水线调度的范围,必须是其中之一:active, inactive
shell
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/29/pipeline_schedules"
json
1[ 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]

获取单个流水线调度#

获取一个项目的流水线调度。

plaintext
GET /projects/:id/pipeline_schedules/:pipeline_schedule_id
AttributeTypeRequiredDescription
idinteger/stringYes项目的 ID 或URL 编码路径
pipeline_schedule_idintegerYes流水线调度 ID
shell
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/29/pipeline_schedules/13"
json
1{ 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}

获取由流水线调度触发的所有流水线#

获取项目中由流水线调度触发的所有流水线。

plaintext
GET /projects/:id/pipeline_schedules/:pipeline_schedule_id/pipelines

支持的属性:

AttributeTypeRequiredDescription
idinteger/stringYes项目的 ID 或URL 编码路径
pipeline_schedule_idintegerYes流水线调度 ID

示例请求:

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

示例响应:

json
1[ 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]

创建新的流水线调度#

创建一个项目的新流水线调度。

plaintext
POST /projects/:id/pipeline_schedules
AttributeTypeRequiredDescription
cronstringYescron 调度,例如:0 1 * * *
descriptionstringYes流水线调度的描述。
idinteger/stringYes项目的 ID 或URL 编码路径
refstringYes被触发的分支或标签名称。短版本(例如 main)和完整版本(例如 refs/heads/mainrefs/tags/main)都可以接受。如果提供了短版本,它会自动扩展为完整版本,但如果 ref 是模糊的,则会被拒绝。
activebooleanNo流水线调度的激活状态。如果设置为 false,流水线调度最初是未激活的(默认:true)。
cron_timezonestringNoActiveSupport::TimeZone 支持的时区,例如:Pacific Time (US & Canada)(默认:UTC)。
shell
curl --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"
json
1{ 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}

编辑流水线调度#

更新项目的流水线调度。更新完成后,它会自动重新调度。

plaintext
PUT /projects/:id/pipeline_schedules/:pipeline_schedule_id
AttributeTypeRequiredDescription
idinteger/stringYes项目的 ID 或URL 编码路径
pipeline_schedule_idintegerYes流水线调度 ID
activebooleanNo流水线调度的激活状态。如果设置为 false,流水线调度最初是未激活的。
cron_timezonestringNoActiveSupport::TimeZone 支持的时区(例如 Pacific Time (US & Canada)),或 TZInfo::Timezone(例如 America/Los_Angeles)。
cronstringNocron 调度,例如:0 1 * * *
descriptionstringNo流水线调度的描述。
refstringNo被触发的分支或标签名称。短版本(例如 main)和完整版本(例如 refs/heads/mainrefs/tags/main)都可以接受。如果提供了短版本,它会自动扩展为完整版本,但如果 ref 是模糊的,则会被拒绝。
shell
curl --request PUT --header "PRIVATE-TOKEN: <your_access_token>" \ --form cron="0 2 * * *" "https://gitlab.example.com/api/v4/projects/29/pipeline_schedules/13"
json
1{ 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}

获取流水线调度的所有权#

更新项目的流水线调度的所有者。

plaintext
POST /projects/:id/pipeline_schedules/:pipeline_schedule_id/take_ownership
AttributeTypeRequiredDescription
idinteger/stringYes项目的 ID 或URL 编码路径
pipeline_schedule_idintegerYes流水线调度 ID
shell
curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/29/pipeline_schedules/13/take_ownership"
json
1{ 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}

删除流水线调度#

删除项目的流水线调度。

plaintext
DELETE /projects/:id/pipeline_schedules/:pipeline_schedule_id
AttributeTypeRequiredDescription
idinteger/stringYes项目的 ID 或URL 编码路径
pipeline_schedule_idintegerYes流水线调度 ID
shell
curl --request DELETE --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/29/pipeline_schedules/13"
json
1{ 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}

立即运行已调度的流水线#

触发一个新的已调度流水线,该流水线立即运行。此流水线的下一次调度运行不受影响。

plaintext
POST /projects/:id/pipeline_schedules/:pipeline_schedule_id/play
AttributeTypeRequiredDescription
idinteger/stringYes项目的 ID 或URL 编码路径
pipeline_schedule_idintegerYes流水线调度 ID

示例请求:

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

示例响应:

json
{ "message": "201 Created" }

流水线调度变量#

创建新的流水线调度变量#

创建一个流水线调度的新变量。

plaintext
POST /projects/:id/pipeline_schedules/:pipeline_schedule_id/variables
AttributeTypeRequiredDescription
idinteger/stringYes项目的 ID 或URL 编码路径
keystringYes变量的 key;不得超过 255 个字符;仅允许 A-Za-z0-9_
pipeline_schedule_idintegerYes流水线调度 ID
valuestringYes变量的 value
variable_typestringNo变量的类型。可用类型有:env_var(默认)和 file
shell
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"
json
{ "key": "NEW_VARIABLE", "variable_type": "env_var", "value": "new value" }

编辑流水线调度变量#

更新流水线调度的变量。

plaintext
PUT /projects/:id/pipeline_schedules/:pipeline_schedule_id/variables/:key
AttributeTypeRequiredDescription
idinteger/stringYes项目的 ID 或URL 编码路径
keystringYes变量的 key
pipeline_schedule_idintegerYes流水线调度 ID
valuestringYes变量的 value
variable_typestringNo变量的类型。可用类型有:env_var(默认)和 file
shell
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"
json
{ "key": "NEW_VARIABLE", "value": "updated value", "variable_type": "env_var" }

删除流水线调度变量#

删除流水线调度的变量。

plaintext
DELETE /projects/:id/pipeline_schedules/:pipeline_schedule_id/variables/:key
AttributeTypeRequiredDescription
idinteger/stringYes项目的 ID 或URL 编码路径
keystringYes变量的 key
pipeline_schedule_idintegerYes流水线调度 ID
shell
curl --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" }