Help us learn about your current experience with the documentation. Take the survey.
作业 API
- Tier: Free, Premium, Ultimate
- Offering: GitLab.com, GitLab Self-Managed, GitLab Dedicated
使用此 API 与 CI/CD 作业 交互。
列出项目作业
获取项目中的作业列表。
默认情况下,此请求每次返回 20 条结果,因为 API 结果支持分页。
此端点同时支持基于偏移量和基于键集的分页,但在请求连续结果页时强烈推荐使用基于键集的分页。
GET /projects/:id/jobs| 属性 | 类型 | 必需 | 描述 |
|---|---|---|---|
id |
整数或字符串 | 是 | 项目的 ID 或 URL 编码路径。 |
scope |
字符串或字符串数组 | 否 | 要显示的作业范围。可以是单个作业状态值或其数组。若未提供 scope,则返回所有作业。 |
order_by |
字符串 | 否 | 按 id 排序返回作业。 |
sort |
字符串 | 否 | 按 asc(升序)或 desc(降序)排序返回作业。默认为 desc。 |
curl --globoff \
--header "PRIVATE-TOKEN: <your_access_token>" \
--url "https://gitlab.example.com/api/v4/projects/1/jobs?scope[]=pending&scope[]=running"响应示例:
[
{
"commit": {
"author_email": "admin@example.com",
"author_name": "Administrator",
"created_at": "2015-12-24T16:51:14.000+01:00",
"id": "0ff3ae198f8601a285adcf5c0fff204ee6fba5fd",
"message": "Test the CI integration.",
"short_id": "0ff3ae19",
"title": "Test the CI integration."
},
"coverage": null,
"archived": false,
"source": "push",
"allow_failure": false,
"created_at": "2015-12-24T15:51:21.802Z",
"started_at": "2015-12-24T17:54:27.722Z",
"finished_at": "2015-12-24T17:54:27.895Z",
"erased_at": null,
"duration": 0.173,
"queued_duration": 0.010,
"artifacts_file": {
"filename": "artifacts.zip",
"size": 1000
},
"artifacts": [
{"file_type": "archive", "size": 1000, "filename": "artifacts.zip", "file_format": "zip"},
{"file_type": "metadata", "size": 186, "filename": "metadata.gz", "file_format": "gzip"},
{"file_type": "trace", "size": 1500, "filename": "job.log", "file_format": "raw"},
{"file_type": "junit", "size": 750, "filename": "junit.xml.gz", "file_format": "gzip"}
],
"artifacts_expire_at": "2016-01-23T17:54:27.895Z",
"tag_list": [
"docker runner", "ubuntu18"
],
"id": 7,
"name": "teaspoon",
"pipeline": {
"id": 6,
"project_id": 1,
"ref": "main",
"sha": "0ff3ae198f8601a285adcf5c0fff204ee6fba5fd",
"status": "pending"
},
"ref": "main",
"runner": {
"id": 32,
"description": "",
"ip_address": null,
"active": true,
"paused": false,
"is_shared": true,
"runner_type": "instance_type",
"name": null,
"online": false,
"status": "offline"
},
"runner_manager": {
"id": 1,
"system_id": "s_89e5e9956577",
"version": "16.11.1",
"revision": "535ced5f",
"platform": "linux",
"architecture": "amd64",
"created_at": "2024-05-01T10:12:02.507Z",
"contacted_at": "2024-05-07T06:30:09.355Z",
"ip_address": "127.0.0.1",
"status": "offline"
},
"stage": "test",
"status": "failed",
"failure_reason": "script_failure",
"tag": false,
"web_url": "https://example.com/foo/bar/-/jobs/7",
"project": {
"ci_job_token_scope_enabled": false
},
"user": {
"id": 1,
"name": "Administrator",
"username": "root",
"state": "active",
"avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon",
"web_url": "http://gitlab.dev/root",
"created_at": "2015-12-21T13:14:24.077Z",
"bio": null,
"location": null,
"public_email": "",
"linkedin": "",
"twitter": "",
"website_url": "",
"organization": ""
}
},
{
"commit": {
"author_email": "admin@example.com",
"author_name": "Administrator",
"created_at": "2015-12-24T16:51:14.000+01:00",
"id": "0ff3ae198f8601a285adcf5c0fff204ee6fba5fd",
"message": "Test the CI integration.",
"short_id": "0ff3ae19",
"title": "Test the CI integration."
},
"coverage": null,
"archived": false,
"source": "push",
"allow_failure": false,
"created_at": "2015-12-24T15:51:21.727Z",
"started_at": "2015-12-24T17:54:24.729Z",
"finished_at": "2015-12-24T17:54:24.921Z",
"erased_at": null,
"duration": 0.192,
"queued_duration": 0.023,
"artifacts_expire_at": "2016-01-23T17:54:24.921Z",
"tag_list": [
"docker runner", "win10-2004"
],
"id": 6,
"name": "rspec:other",
"pipeline": {
"id": 6,
"project_id": 1,
"ref": "main",
"sha": "0ff3ae198f8601a285adcf5c0fff204ee6fba5fd",
"status": "pending"
},
"ref": "main",
"artifacts": [],
"runner": null,
"runner_manager": null,
"stage": "test",
"status": "failed",
"failure_reason": "stuck_or_timeout_failure",
"tag": false,
"web_url": "https://example.com/foo/bar/-/jobs/6",
"project": {
"ci_job_token_scope_enabled": false
},
"user": {
"id": 1,
"name": "Administrator",
"username": "root",
"state": "active",
"avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon",
"web_url": "http://gitlab.dev/root",
"created_at": "2015-12-21T13:14:24.077Z",
"bio": null,
"location": null,
"public_email": "",
"linkedin": "",
"twitter": "",
"website_url": "",
"organization": ""
}
}
]作业状态值
作业响应中的 status 字段和用于过滤作业的 scope 参数使用以下值:
canceled:作业被手动取消或自动中止。canceling:作业正在取消中,但after_script仍在运行。created:作业已创建但尚未处理。failed:作业执行失败。manual:作业需要手动操作才能启动。pending:作业在队列中等待 runner。preparing:Runner 正在准备执行环境。running:作业正在 runner 上执行。scheduled:作业已调度但执行尚未开始。skipped:作业因条件或依赖项被跳过。success:作业成功完成。waiting_for_resource:作业正在等待资源可用。
列出流水线作业
获取流水线的作业列表。
默认情况下,此请求每次返回 20 条结果,因为 API 结果支持分页。
此端点:
- 返回任何流水线的数据,包括子流水线。
- 默认不在响应中返回重试的作业。
- 按 ID 降序排序作业(最新的在前)。
GET /projects/:id/pipelines/:pipeline_id/jobs| 属性 | 类型 | 必需 | 描述 |
|---|---|---|---|
id |
整数/字符串 | 是 | 项目的 ID 或 URL 编码路径。 |
pipeline_id |
整数 | 是 | 流水线的 ID。也可在 CI 作业中使用预定义 CI 变量 CI_PIPELINE_ID 获取。 |
include_retried |
布尔值 | 否 | 在响应中包含重试的作业。默认为 false。 |
scope |
字符串 或 字符串数组 | 否 | 要显示的作业范围。可以是单个作业状态值或其数组。若未提供 scope,则返回所有作业。 |
curl --globoff \
--header "PRIVATE-TOKEN: <your_access_token>" \
--url "https://gitlab.example.com/api/v4/projects/1/pipelines/6/jobs?scope[]=pending&scope[]=running"响应示例:
[
{
"commit": {
"author_email": "admin@example.com",
"author_name": "Administrator",
"created_at": "2015-12-24T16:51:14.000+01:00",
"id": "0ff3ae198f8601a285adcf5c0fff204ee6fba5fd",
"message": "Test the CI integration.",
"short_id": "0ff3ae19",
"title": "Test the CI integration."
},
"coverage": null,
"archived": false,
"source": "push",
"allow_failure": false,
"created_at": "2015-12-24T15:51:21.727Z",
"started_at": "2015-12-24T17:54:24.729Z",
"finished_at": "2015-12-24T17:54:24.921Z",
"erased_at": null,
"duration": 0.192,
"queued_duration": 0.023,
"artifacts_expire_at": "2016-01-23T17:54:24.921Z",
"tag_list": [
"docker runner", "ubuntu18"
],
"id": 6,
"name": "rspec:other",
"pipeline": {
"id": 6,
"project_id": 1,
"ref": "main",
"sha": "0ff3ae198f8601a285adcf5c0fff204ee6fba5fd",
"status": "pending"
},
"ref": "main",
"artifacts": [],
"runner": {
"id": 32,
"description": "",
"ip_address": null,
"active": true,
"paused": false,
"is_shared": true,
"runner_type": "instance_type",
"name": null,
"online": false,
"status": "offline"
},
"runner_manager": {
"id": 1,
"system_id": "s_89e5e9956577",
"version": "16.11.1",
"revision": "535ced5f",
"platform": "linux",
"architecture": "amd64",
"created_at": "2024-05-01T10:12:02.507Z",
"contacted_at": "2024-05-07T06:30:09.355Z",
"ip_address": "127.0.0.1",
},
"stage": "test",
"status": "failed",
"failure_reason": "stuck_or_timeout_failure",
"tag": false,
"web_url": "https://example.com/foo/bar/-/jobs/6",
"project": {
"ci_job_token_scope_enabled": false
},
"user": {
"id": 1,
"name": "Administrator",
"username": "root",
"state": "active",
"avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon",
"web_url": "http://gitlab.dev/root",
"created_at": "2015-12-21T13:14:24.077Z",
"bio": null,
"location": null,
"public_email": "",
"linkedin": "",
"twitter": "",
"website_url": "",
"organization": ""
}
},
{
"commit": {
"author_email": "admin@example.com",
"author_name": "Administrator",
"created_at": "2015-12-24T16:51:14.000+01:00",
"id": "0ff3ae198f8601a285adcf5c0fff204ee6fba5fd",
"message": "Test the CI integration.",
"short_id": "0ff3ae19",
"title": "Test the CI integration."
},
"coverage": null,
"archived": false,
"source": "push",
"allow_failure": false,
"created_at": "2015-12-24T15:51:21.802Z",
"started_at": "2015-12-24T17:54:27.722Z",
"finished_at": "2015-12-24T17:54:27.895Z",
"erased_at": null,
"duration": 0.173,
"queued_duration": 0.023,
"artifacts_file": {
"filename": "artifacts.zip",
"size": 1000
},
"artifacts": [
{"file_type": "archive", "size": 1000, "filename": "artifacts.zip", "file_format": "zip"},
{"file_type": "metadata", "size": 186, "filename": "metadata.gz", "file_format": "gzip"},
{"file_type": "trace", "size": 1500, "filename": "job.log", "file_format": "raw"},
{"file_type": "junit", "size": 750, "filename": "junit.xml.gz", "file_format": "gzip"}
],
"artifacts_expire_at": "2016-01-23T17:54:27.895Z",
"tag_list": [
"docker runner", "ubuntu18"
],
"id": 7,
"name": "teaspoon",
"pipeline": {
"id": 6,
"project_id": 1,
"ref": "main",
"sha": "0ff3ae198f8601a285adcf5c0fff204ee6fba5fd",
"status": "pending"
},
"ref": "main",
"runner": null,
"runner_manager": null,
"stage": "test",
"status": "failed",
"failure_reason": "script_failure",
"tag": false,
"web_url": "https://example.com/foo/bar/-/jobs/7",
"project": {
"ci_job_token_scope_enabled": false
},
"user": {
"id": 1,
"name": "Administrator",
"username": "root",
"state": "active",
"avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon",
"web_url": "http://gitlab.dev/root",
"created_at": "2015-12-21T13:14:24.077Z",
"bio": null,
"location": null,
"public_email": "",
"linkedin": "",
"twitter": "",
"website_url": "",
"organization": ""
}
}
]列出流水线触发作业
获取流水线的触发作业列表。
GET /projects/:id/pipelines/:pipeline_id/bridges| 属性 | 类型 | 必需 | 描述 |
|---|---|---|---|
id |
整数/字符串 | 是 | 项目的 ID 或 URL 编码路径。 |
pipeline_id |
整数 | 是 | 流水线的 ID。 |
scope |
字符串 或 字符串数组 | 否 | 要显示的作业范围。可以是单个作业状态值或其数组。若未提供 scope,则返回所有作业。 |
curl --globoff \
--header "PRIVATE-TOKEN: <your_access_token>" \
--url "https://gitlab.example.com/api/v4/projects/1/pipelines/6/bridges?scope[]=pending&scope[]=running"响应示例:
[
{
"commit": {
"author_email": "admin@example.com",
"author_name": "Administrator",
"created_at": "2015-12-24T16:51:14.000+01:00",
"id": "0ff3ae198f8601a285adcf5c0fff204ee6fba5fd",
"message": "Test the CI integration.",
"short_id": "0ff3ae19",
"title": "Test the CI integration."
},
"coverage": null,
"archived": false,
"source": "push",
"allow_failure": false,
"created_at": "2015-12-24T15:51:21.802Z",
"started_at": "2015-12-24T17:54:27.722Z",
"finished_at": "2015-12-24T17:58:27.895Z",
"erased_at": null,
"duration": 240,
"queued_duration": 0.123,
"id": 7,
"name": "teaspoon",
"pipeline": {
"id": 6,
"project_id": 1,
"ref": "main",
"sha": "0ff3ae198f8601a285adcf5c0fff204ee6fba5fd",
"status": "pending",
"created_at": "2015-12-24T15:50:16.123Z",
"updated_at": "2015-12-24T18:00:44.432Z",
"web_url": "https://example.com/foo/bar/pipelines/6"
},
"ref": "main",
"stage": "test",
"status": "pending",
"tag": false,
"web_url": "https://example.com/foo/bar/-/jobs/7",
"project": {
"ci_job_token_scope_enabled": false
},
"user": {
"id": 1,
"name": "Administrator",
"username": "root",
"state": "active",
"avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon",
"web_url": "http://gitlab.dev/root",
"created_at": "2015-12-21T13:14:24.077Z",
"bio": null,
"location": null,
"public_email": "",
"linkedin": "",
"twitter": "",
"website_url": "",
"organization": ""
},
"downstream_pipeline": {
"id": 5,
"sha": "f62a4b2fb89754372a346f24659212eb8da13601",
"ref": "main",
"status": "pending",
"created_at": "2015-12-24T17:54:27.722Z",
"updated_at": "2015-12-24T17:58:27.896Z",
"web_url": "https://example.com/diaspora/diaspora-client/pipelines/5"
}
}
]获取作业令牌的作业
检索生成作业令牌的作业。
GET /job示例(必须作为 CI/CD 作业 的 script 部分运行):
# 选项 1
curl --header "Authorization: Bearer $CI_JOB_TOKEN" \
--url "${CI_API_V4_URL}/job"
# 选项 2
curl --header "JOB-TOKEN: $CI_JOB_TOKEN" \
--url "${CI_API_V4_URL}/job"
# 选项 3
curl --url "${CI_API_V4_URL}/job?job_token=$CI_JOB_TOKEN"响应示例:
{
"commit": {
"author_email": "admin@example.com",
"author_name": "Administrator",
"created_at": "2015-12-24T16:51:14.000+01:00",
"id": "0ff3ae198f8601a285adcf5c0fff204ee6fba5fd",
"message": "Test the CI integration.",
"short_id": "0ff3ae19",
"title": "Test the CI integration."
},
"coverage": null,
"archived": false,
"source": "push",
"allow_failure": false,
"created_at": "2015-12-24T15:51:21.880Z",
"started_at": "2015-12-24T17:54:30.733Z",
"finished_at": "2015-12-24T17:54:31.198Z",
"erased_at": null,
"duration": 0.465,
"queued_duration": 0.123,
"artifacts_expire_at": "2016-01-23T17:54:31.198Z",
"id": 8,
"name": "rubocop",
"pipeline": {
"id": 6,
"project_id": 1,
"ref": "main",
"sha": "0ff3ae198f8601a285adcf5c0fff204ee6fba5fd",
"status": "pending"
},
"ref": "main",
"artifacts": [],
"runner": null,
"runner_manager": null,
"stage": "test",
"status": "failed",
"failure_reason": "script_failure",
"tag": false,
"web_url": "https://example.com/foo/bar/-/jobs/8",
"project": {
"ci_job_token_scope_enabled": false
},
"user": {
"id": 1,
"name": "Administrator",
"username": "root",
"state": "active",
"avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon",
"web_url": "http://gitlab.dev/root",
"created_at": "2015-12-21T13:14:24.077Z",
"bio": null,
"location": null,
"public_email": "",
"linkedin": "",
"twitter": "",
"website_url": "",
"organization": ""
}
}通过 CI_JOB_TOKEN 获取 Kubernetes 的 GitLab 代理
检索生成 CI_JOB_TOKEN 的作业,以及允许的代理列表。
GET /job/allowed_agents支持的属性:
| 属性 | 类型 | 必需 | 描述 |
|---|---|---|---|
CI_JOB_TOKEN |
字符串 | 是 | 与 GitLab 提供的 CI_JOB_TOKEN 变量关联的令牌值。 |
请求示例:
# 选项 1
curl --header "JOB-TOKEN: <CI_JOB_TOKEN>" \
--url "https://gitlab.example.com/api/v4/job/allowed_agents"
# 选项 2
curl --url "https://gitlab.example.com/api/v4/job/allowed_agents?job_token=<CI_JOB_TOKEN>"响应示例:
{
"allowed_agents": [
{
"id": 1,
"config_project": {
"id": 1,
"description": null,
"name": "project1",
"name_with_namespace": "John Doe2 / project1",
"path": "project1",
"path_with_namespace": "namespace1/project1",
"created_at": "2022-11-16T14:51:50.579Z"
}
}
],
"job": {
"id": 1
},
"pipeline": {
"id": 2
},
"project": {
"id": 1,
"groups": [
{
"id": 1
},
{
"id": 2
},
{
"id": 3
}
]
},
"user": {
"id": 2,
"name": "John Doe3",
"username": "user2",
"state": "active",
"avatar_url": "https://www.gravatar.com/avatar/10fc7f102b",
"web_url": "http://localhost/user2"
}
}获取单个作业
获取项目的单个作业。
GET /projects/:id/jobs/:job_id| 属性 | 类型 | 必需 | 描述 |
|---|---|---|---|
id |
整数/字符串 | 是 | 项目的 ID 或 URL 编码路径。 |
job_id |
整数 | 是 | 作业的 ID。 |
curl --header "PRIVATE-TOKEN: <your_access_token>" \
--url "https://gitlab.example.com/api/v4/projects/1/jobs/8"响应示例:
{
"commit": {
"author_email": "admin@example.com",
"author_name": "Administrator",
"created_at": "2015-12-24T16:51:14.000+01:00",
"id": "0ff3ae198f8601a285adcf5c0fff204ee6fba5fd",
"message": "Test the CI integration.",
"short_id": "0ff3ae19",
"title": "Test the CI integration."
},
"coverage": null,
"archived": false,
"source": "push",
"allow_failure": false,
"created_at": "2015-12-24T15:51:21.880Z",
"started_at": "2015-12-24T17:54:30.733Z",
"finished_at": "2015-12-24T17:54:31.198Z",
"erased_at": null,
"duration": 0.465,
"queued_duration": 0.010,
"artifacts_expire_at": "2016-01-23T17:54:31.198Z",
"tag_list": [
"docker runner", "macos-10.15"
],
"id": 8,
"name": "rubocop",
"pipeline": {
"id": 6,
"project_id": 1,
"ref": "main",
"sha": "0ff3ae198f8601a285adcf5c0fff204ee6fba5fd",
"status": "pending"
},
"ref": "main",
"artifacts": [],
"runner": null,
"runner_manager": null,
"stage": "test",
"status": "failed",
"tag": false,
"web_url": "https://example.com/foo/bar/-/jobs/8",
"project": {
"ci_job_token_scope_enabled": false
},
"user": {
"id": 1,
"name": "Administrator",
"username": "root",
"state": "active",
"avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon",
"web_url": "http://gitlab.dev/root",
"created_at": "2015-12-21T13:14:24.077Z",
"bio": null,
"location": null,
"public_email": "",
"linkedin": "",
"twitter": "",
"website_url": "",
"organization": ""
}
}获取日志文件
获取项目特定作业的日志(跟踪)。
GET /projects/:id/jobs/:job_id/trace| 属性 | 类型 | 必需 | 描述 |
|---|---|---|---|
id |
整数/字符串 | 是 | 项目的 ID 或 URL 编码路径。 |
job_id |
整数 | 是 | 作业的 ID。 |
curl --location \
--header "PRIVATE-TOKEN: <your_access_token>" \
--url "https://gitlab.example.com/api/v4/projects/1/jobs/8/trace"可能的响应状态码:
| 状态 | 描述 |
|---|---|
| 200 | 返回日志文件 |
| 404 | 未找到作业或无日志文件 |
取消作业
取消项目的单个作业。
POST /projects/:id/jobs/:job_id/cancel| 属性 | 类型 | 必需 | 描述 |
|---|---|---|---|
id |
整数/字符串 | 是 | 项目的 ID 或 URL 编码路径。 |
job_id |
整数 | 是 | 作业的 ID。 |
force |
布尔值 | 否 | 设置为 true 时强制取消处于 canceling 状态的作业。 |
curl --request POST \
--header "PRIVATE-TOKEN: <your_access_token>" \
--url "https://gitlab.example.com/api/v4/projects/1/jobs/1/cancel"响应示例:
{
"commit": {
"author_email": "admin@example.com",
"author_name": "Administrator",
"created_at": "2015-12-24T16:51:14.000+01:00",
"id": "0ff3ae198f8601a285adcf5c0fff204ee6fba5fd",
"message": "Test the CI integration.",
"short_id": "0ff3ae19",
"title": "Test the CI integration."
},
"coverage": null,
"archived": false,
"source": "push",
"allow_failure": false,
"created_at": "2016-01-11T10:13:33.506Z",
"started_at": "2016-01-11T10:14:09.526Z",
"finished_at": null,
"erased_at": null,
"duration": 8,
"queued_duration": 0.010,
"id": 1,
"name": "rubocop",
"ref": "main",
"artifacts": [],
"runner": null,
"runner_manager": null,
"stage": "test",
"status": "canceled",
"tag": false,
"web_url": "https://example.com/foo/bar/-/jobs/1",
"project": {
"ci_job_token_scope_enabled": false
},
"user": null
}重试作业
重试项目的单个作业。
POST /projects/:id/jobs/:job_id/retry| 属性 | 类型 | 必需 | 描述 |
|---|---|---|---|
id |
整数/字符串 | 是 | 项目的 ID 或 URL 编码路径。 |
job_id |
整数 | 是 | 作业的 ID。 |
curl --request POST \
--header "PRIVATE-TOKEN: <your_access_token>" \
--url "https://gitlab.example.com/api/v4/projects/1/jobs/1/retry"响应示例:
{
"commit": {
"author_email": "admin@example.com",
"author_name": "Administrator",
"created_at": "2015-12-24T16:51:14.000+01:00",
"id": "0ff3ae198f8601a285adcf5c0fff204ee6fba5fd",
"message": "Test the CI integration.",
"short_id": "0ff3ae19",
"title": "Test the CI integration."
},
"coverage": null,
"archived": false,
"source": "push",
"allow_failure": false,
"created_at": "2016-01-11T10:13:33.506Z",
"started_at": null,
"finished_at": null,
"erased_at": null,
"duration": null,
"queued_duration": 0.010,
"id": 1,
"name": "rubocop",
"ref": "main",
"artifacts": [],
"runner": null,
"runner_manager": null,
"stage": "test",
"status": "pending",
"tag": false,
"web_url": "https://example.com/foo/bar/-/jobs/1",
"project": {
"ci_job_token_scope_enabled": false
},
"user": null
}在 GitLab 17.0 之前,此端点不支持触发作业。
擦除作业
擦除项目的单个作业(删除作业产物和作业日志)。
POST /projects/:id/jobs/:job_id/erase参数
| 属性 | 类型 | 必需 | 描述 |
|---|---|---|---|
id |
整数/字符串 | 是 | 项目的 ID 或 URL 编码路径。 |
job_id |
整数 | 是 | 作业的 ID。 |
请求示例
curl --request POST \
--header "PRIVATE-TOKEN: <your_access_token>" \
--url "https://gitlab.example.com/api/v4/projects/1/jobs/1/erase"响应示例:
{
"commit": {
"author_email": "admin@example.com",
"author_name": "Administrator",
"created_at": "2015-12-24T16:51:14.000+01:00",
"id": "0ff3ae198f8601a285adcf5c0fff204ee6fba5fd",
"message": "Test the CI integration.",
"short_id": "0ff3ae19",
"title": "Test the CI integration."
},
"coverage": null,
"archived": false,
"source": "push",
"allow_failure": false,
"download_url": null,
"id": 1,
"name": "rubocop",
"ref": "main",
"artifacts": [],
"runner": null,
"runner_manager": null,
"stage": "test",
"created_at": "2016-01-11T10:13:33.506Z",
"started_at": "2016-01-11T10:13:33.506Z",
"finished_at": "2016-01-11T10:15:10.506Z",
"erased_at": "2016-01-11T11:30:19.914Z",
"duration": 97.0,
"queued_duration": 0.010,
"status": "failed",
"tag": false,
"web_url": "https://example.com/foo/bar/-/jobs/1",
"project": {
"ci_job_token_scope_enabled": false
},
"user": null
}您无法通过 API 删除已归档的作业,但可以删除特定日期前完成的作业产物和日志。
运行作业
对于状态为手动(manual)的作业,触发操作以启动作业。
POST /projects/:id/jobs/:job_id/play| 属性 | 类型 | 必需 | 描述 |
|---|---|---|---|
id |
整数/字符串 | 是 | 项目的 ID 或 URL 编码路径。 |
job_id |
整数 | 是 | 作业的 ID。 |
job_variables_attributes |
哈希数组 | 否 | 包含作业可用自定义变量的数组。 |
请求示例:
curl --request POST \
--header "PRIVATE-TOKEN: <your_access_token>" \
--header "Content-Type: application/json" \
--data @variables.json \
--url "https://gitlab.example.com/api/v4/projects/1/jobs/1/play"@variables.json 结构如下:
{
"job_variables_attributes": [
{
"key": "TEST_VAR_1",
"value": "test1"
},
{
"key": "TEST_VAR_2",
"value": "test2"
}
]
}响应示例:
{
"commit": {
"author_email": "admin@example.com",
"author_name": "Administrator",
"created_at": "2015-12-24T16:51:14.000+01:00",
"id": "0ff3ae198f8601a285adcf5c0fff204ee6fba5fd",
"message": "Test the CI integration.",
"short_id": "0ff3ae19",
"title": "Test the CI integration."
},
"coverage": null,
"archived": false,
"source": "push",
"allow_failure": false,
"created_at": "2016-01-11T10:13:33.506Z",
"started_at": null,
"finished_at": null,
"erased_at": null,
"duration": null,
"queued_duration": 0.010,
"id": 1,
"name": "rubocop",
"ref": "main",
"artifacts": [],
"runner": null,
"runner_manager": null,
"stage": "test",
"status": "pending",
"tag": false,
"web_url": "https://example.com/foo/bar/-/jobs/1",
"project": {
"ci_job_token_scope_enabled": false
},
"user": null
}