作业 API

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

列出项目作业#

History
    • 支持 keyset 分页功能引入于极狐GitLab 15.9。

获取项目中的作业列表。作业按其 ID 的降序排序。

默认情况下,此请求一次返回 20 个结果,因为 API 结果已分页

此端点支持基于偏移的和 [基于 keyset 的](rest/_index.md#keyset-based-pagination)分页,但强烈建议在请求连续页面的结果时使用基于 keyset 的分页。
plaintext
GET /projects/:id/jobs
属性类型必需描述
idinteger/string项目的 ID 或 URL 编码的路径
scopestring array of strings要显示的作业范围。以下之一或数组:createdpendingrunningfailedsuccesscanceledskippedwaiting_for_resourcemanual。如果未提供 scope,则返回所有作业。
shell
curl --globoff \ --header "PRIVATE-TOKEN: <your_access_token>" \ --url "https://gitlab.example.com/api/v4/projects/1/jobs?scope[]=pending&scope[]=running"

响应示例:

json
1[ 2 { 3 "commit": { 4 "author_email": "admin@example.com", 5 "author_name": "Administrator", 6 "created_at": "2015-12-24T16:51:14.000+01:00", 7 "id": "0ff3ae198f8601a285adcf5c0fff204ee6fba5fd", 8 "message": "Test the CI integration.", 9 "short_id": "0ff3ae19", 10 "title": "Test the CI integration." 11 }, 12 "coverage": null, 13 "archived": false, 14 "source": "push", 15 "allow_failure": false, 16 "created_at": "2015-12-24T15:51:21.802Z", 17 "started_at": "2015-12-24T17:54:27.722Z", 18 "finished_at": "2015-12-24T17:54:27.895Z", 19 "erased_at": null, 20 "duration": 0.173, 21 "queued_duration": 0.010, 22 "artifacts_file": { 23 "filename": "artifacts.zip", 24 "size": 1000 25 }, 26 "artifacts": [ 27 {"file_type": "archive", "size": 1000, "filename": "artifacts.zip", "file_format": "zip"}, 28 {"file_type": "metadata", "size": 186, "filename": "metadata.gz", "file_format": "gzip"}, 29 {"file_type": "trace", "size": 1500, "filename": "job.log", "file_format": "raw"}, 30 {"file_type": "junit", "size": 750, "filename": "junit.xml.gz", "file_format": "gzip"} 31 ], 32 "artifacts_expire_at": "2016-01-23T17:54:27.895Z", 33 "tag_list": [ 34 "docker runner", "ubuntu18" 35 ], 36 "id": 7, 37 "name": "teaspoon", 38 "pipeline": { 39 "id": 6, 40 "project_id": 1, 41 "ref": "main", 42 "sha": "0ff3ae198f8601a285adcf5c0fff204ee6fba5fd", 43 "status": "pending" 44 }, 45 "ref": "main", 46 "runner": { 47 "id": 32, 48 "description": "", 49 "ip_address": null, 50 "active": true, 51 "paused": false, 52 "is_shared": true, 53 "runner_type": "instance_type", 54 "name": null, 55 "online": false, 56 "status": "offline" 57 }, 58 "runner_manager": { 59 "id": 1, 60 "system_id": "s_89e5e9956577", 61 "version": "16.11.1", 62 "revision": "535ced5f", 63 "platform": "linux", 64 "architecture": "amd64", 65 "created_at": "2024-05-01T10:12:02.507Z", 66 "contacted_at": "2024-05-07T06:30:09.355Z", 67 "ip_address": "127.0.0.1", 68 "status": "offline" 69 }, 70 "stage": "test", 71 "status": "failed", 72 "failure_reason": "script_failure", 73 "tag": false, 74 "web_url": "https://example.com/foo/bar/-/jobs/7", 75 "project": { 76 "ci_job_token_scope_enabled": false 77 }, 78 "user": { 79 "id": 1, 80 "name": "Administrator", 81 "username": "root", 82 "state": "active", 83 "avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon", 84 "web_url": "http://gitlab.dev/root", 85 "created_at": "2015-12-21T13:14:24.077Z", 86 "bio": null, 87 "location": null, 88 "public_email": "", 89 "skype": "", 90 "linkedin": "", 91 "twitter": "", 92 "website_url": "", 93 "organization": "" 94 } 95 }, 96 { 97 "commit": { 98 "author_email": "admin@example.com", 99 "author_name": "Administrator", 100 "created_at": "2015-12-24T16:51:14.000+01:00", 101 "id": "0ff3ae198f8601a285adcf5c0fff204ee6fba5fd", 102 "message": "Test the CI integration.", 103 "short_id": "0ff3ae19", 104 "title": "Test the CI integration." 105 }, 106 "coverage": null, 107 "archived": false, 108 "source": "push", 109 "allow_failure": false, 110 "created_at": "2015-12-24T15:51:21.727Z", 111 "started_at": "2015-12-24T17:54:24.729Z", 112 "finished_at": "2015-12-24T17:54:24.921Z", 113 "erased_at": null, 114 "duration": 0.192, 115 "queued_duration": 0.023, 116 "artifacts_expire_at": "2016-01-23T17:54:24.921Z", 117 "tag_list": [ 118 "docker runner", "win10-2004" 119 ], 120 "id": 6, 121 "name": "rspec:other", 122 "pipeline": { 123 "id": 6, 124 "project_id": 1, 125 "ref": "main", 126 "sha": "0ff3ae198f8601a285adcf5c0fff204ee6fba5fd", 127 "status": "pending" 128 }, 129 "ref": "main", 130 "artifacts": [], 131 "runner": null, 132 "runner_manager": null, 133 "stage": "test", 134 "status": "failed", 135 "failure_reason": "stuck_or_timeout_failure", 136 "tag": false, 137 "web_url": "https://example.com/foo/bar/-/jobs/6", 138 "project": { 139 "ci_job_token_scope_enabled": false 140 }, 141 "user": { 142 "id": 1, 143 "name": "Administrator", 144 "username": "root", 145 "state": "active", 146 "avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon", 147 "web_url": "http://gitlab.dev/root", 148 "created_at": "2015-12-21T13:14:24.077Z", 149 "bio": null, 150 "location": null, 151 "public_email": "", 152 "skype": "", 153 "linkedin": "", 154 "twitter": "", 155 "website_url": "", 156 "organization": "" 157 } 158 } 159]

列出流水线作业#

获取流水线的作业列表。

默认情况下,此请求一次返回 20 个结果,因为 API 结果已分页

此端点:

plaintext
GET /projects/:id/pipelines/:pipeline_id/jobs
属性类型必需描述
idinteger/string项目的 ID 或 URL 编码的路径
pipeline_idinteger流水线的 ID。也可以在 CI 作业中通过 预定义的 CI 变量 CI_PIPELINE_ID 获取。
include_retriedboolean在响应中包括重试的作业。默认值为 false
scopestring array of strings要显示的作业范围。以下之一或数组:createdpendingrunningfailedsuccesscanceledskippedwaiting_for_resourcemanual。如果未提供 scope,则返回所有作业。
shell
curl --globoff \ --header "PRIVATE-TOKEN: <your_access_token>" \ --url "https://gitlab.example.com/api/v4/projects/1/pipelines/6/jobs?scope[]=pending&scope[]=running"

响应示例:

json
1[ 2 { 3 "commit": { 4 "author_email": "admin@example.com", 5 "author_name": "Administrator", 6 "created_at": "2015-12-24T16:51:14.000+01:00", 7 "id": "0ff3ae198f8601a285adcf5c0fff204ee6fba5fd", 8 "message": "Test the CI integration.", 9 "short_id": "0ff3ae19", 10 "title": "Test the CI integration." 11 }, 12 "coverage": null, 13 "archived": false, 14 "source": "push", 15 "allow_failure": false, 16 "created_at": "2015-12-24T15:51:21.727Z", 17 "started_at": "2015-12-24T17:54:24.729Z", 18 "finished_at": "2015-12-24T17:54:24.921Z", 19 "erased_at": null, 20 "duration": 0.192, 21 "queued_duration": 0.023, 22 "artifacts_expire_at": "2016-01-23T17:54:24.921Z", 23 "tag_list": [ 24 "docker runner", "ubuntu18" 25 ], 26 "id": 6, 27 "name": "rspec:other", 28 "pipeline": { 29 "id": 6, 30 "project_id": 1, 31 "ref": "main", 32 "sha": "0ff3ae198f8601a285adcf5c0fff204ee6fba5fd", 33 "status": "pending" 34 }, 35 "ref": "main", 36 "artifacts": [], 37 "runner": { 38 "id": 32, 39 "description": "", 40 "ip_address": null, 41 "active": true, 42 "paused": false, 43 "is_shared": true, 44 "runner_type": "instance_type", 45 "name": null, 46 "online": false, 47 "status": "offline" 48 }, 49 "runner_manager": { 50 "id": 1, 51 "system_id": "s_89e5e9956577", 52 "version": "16.11.1", 53 "revision": "535ced5f", 54 "platform": "linux", 55 "architecture": "amd64", 56 "created_at": "2024-05-01T10:12:02.507Z", 57 "contacted_at": "2024-05-07T06:30:09.355Z", 58 "ip_address": "127.0.0.1" 59 }, 60 "stage": "test", 61 "status": "failed", 62 "failure_reason": "stuck_or_timeout_failure", 63 "tag": false, 64 "web_url": "https://example.com/foo/bar/-/jobs/6", 65 "project": { 66 "ci_job_token_scope_enabled": false 67 }, 68 "user": { 69 "id": 1, 70 "name": "Administrator", 71 "username": "root", 72 "state": "active", 73 "avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon", 74 "web_url": "http://gitlab.dev/root", 75 "created_at": "2015-12-21T13:14:24.077Z", 76 "bio": null, 77 "location": null, 78 "public_email": "", 79 "skype": "", 80 "linkedin": "", 81 "twitter": "", 82 "website_url": "", 83 "organization": "" 84 } 85 }, 86 { 87 "commit": { 88 "author_email": "admin@example.com", 89 "author_name": "Administrator", 90 "created_at": "2015-12-24T16:51:14.000+01:00", 91 "id": "0ff3ae198f8601a285adcf5c0fff204ee6fba5fd", 92 "message": "Test the CI integration.", 93 "short_id": "0ff3ae19", 94 "title": "Test the CI integration." 95 }, 96 "coverage": null, 97 "archived": false, 98 "source": "push", 99 "allow_failure": false, 100 "created_at": "2015-12-24T15:51:21.802Z", 101 "started_at": "2015-12-24T17:54:27.722Z", 102 "finished_at": "2015-12-24T17:54:27.895Z", 103 "erased_at": null, 104 "duration": 0.173, 105 "queued_duration": 0.023, 106 "artifacts_file": { 107 "filename": "artifacts.zip", 108 "size": 1000 109 }, 110 "artifacts": [ 111 {"file_type": "archive", "size": 1000, "filename": "artifacts.zip", "file_format": "zip"}, 112 {"file_type": "metadata", "size": 186, "filename": "metadata.gz", "file_format": "gzip"}, 113 {"file_type": "trace", "size": 1500, "filename": "job.log", "file_format": "raw"}, 114 {"file_type": "junit", "size": 750, "filename": "junit.xml.gz", "file_format": "gzip"} 115 ], 116 "artifacts_expire_at": "2016-01-23T17:54:27.895Z", 117 "tag_list": [ 118 "docker runner", "ubuntu18" 119 ], 120 "id": 7, 121 "name": "teaspoon", 122 "pipeline": { 123 "id": 6, 124 "project_id": 1, 125 "ref": "main", 126 "sha": "0ff3ae198f8601a285adcf5c0fff204ee6fba5fd", 127 "status": "pending" 128 }, 129 "ref": "main", 130 "runner": null, 131 "runner_manager": null, 132 "stage": "test", 133 "status": "failed", 134 "failure_reason": "script_failure", 135 "tag": false, 136 "web_url": "https://example.com/foo/bar/-/jobs/7", 137 "project": { 138 "ci_job_token_scope_enabled": false 139 }, 140 "user": { 141 "id": 1, 142 "name": "Administrator", 143 "username": "root", 144 "state": "active", 145 "avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon", 146 "web_url": "http://gitlab.dev/root", 147 "created_at": "2015-12-21T13:14:24.077Z", 148 "bio": null, 149 "location": null, 150 "public_email": "", 151 "skype": "", 152 "linkedin": "", 153 "twitter": "", 154 "website_url": "", 155 "organization": "" 156 } 157 } 158]

列出流水线触发作业#

获取流水线的触发作业列表。

plaintext
GET /projects/:id/pipelines/:pipeline_id/bridges
属性类型必需描述
idinteger/string项目的 ID 或 URL 编码的路径
pipeline_idinteger流水线的 ID。
scopestring array of strings要显示的作业范围。以下之一或数组:createdpendingrunningfailedsuccesscanceledskippedwaiting_for_resourcemanual。如果未提供 scope,则返回所有作业。
shell
curl --globoff \ --header "PRIVATE-TOKEN: <your_access_token>" \ --url "https://gitlab.example.com/api/v4/projects/1/pipelines/6/bridges?scope[]=pending&scope[]=running"

响应示例:

json
1[ 2 { 3 "commit": { 4 "author_email": "admin@example.com", 5 "author_name": "Administrator", 6 "created_at": "2015-12-24T16:51:14.000+01:00", 7 "id": "0ff3ae198f8601a285adcf5c0fff204ee6fba5fd", 8 "message": "Test the CI integration.", 9 "short_id": "0ff3ae19", 10 "title": "Test the CI integration." 11 }, 12 "coverage": null, 13 "archived": false, 14 "source": "push", 15 "allow_failure": false, 16 "created_at": "2015-12-24T15:51:21.802Z", 17 "started_at": "2015-12-24T17:54:27.722Z", 18 "finished_at": "2015-12-24T17:58:27.895Z", 19 "erased_at": null, 20 "duration": 240, 21 "queued_duration": 0.123, 22 "id": 7, 23 "name": "teaspoon", 24 "pipeline": { 25 "id": 6, 26 "project_id": 1, 27 "ref": "main", 28 "sha": "0ff3ae198f8601a285adcf5c0fff204ee6fba5fd", 29 "status": "pending", 30 "created_at": "2015-12-24T15:50:16.123Z", 31 "updated_at": "2015-12-24T18:00:44.432Z", 32 "web_url": "https://example.com/foo/bar/pipelines/6" 33 }, 34 "ref": "main", 35 "stage": "test", 36 "status": "pending", 37 "tag": false, 38 "web_url": "https://example.com/foo/bar/-/jobs/7", 39 "project": { 40 "ci_job_token_scope_enabled": false 41 }, 42 "user": { 43 "id": 1, 44 "name": "Administrator", 45 "username": "root", 46 "state": "active", 47 "avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon", 48 "web_url": "http://gitlab.dev/root", 49 "created_at": "2015-12-21T13:14:24.077Z", 50 "bio": null, 51 "location": null, 52 "public_email": "", 53 "skype": "", 54 "linkedin": "", 55 "twitter": "", 56 "website_url": "", 57 "organization": "" 58 }, 59 "downstream_pipeline": { 60 "id": 5, 61 "sha": "f62a4b2fb89754372a346f24659212eb8da13601", 62 "ref": "main", 63 "status": "pending", 64 "created_at": "2015-12-24T17:54:27.722Z", 65 "updated_at": "2015-12-24T17:58:27.896Z", 66 "web_url": "https://example.com/diaspora/diaspora-client/pipelines/5" 67 } 68 } 69]

获取作业令牌的作业#

检索生成作业令牌的作业。

plaintext
GET /job

示例(必须作为 CI/CD 作业script 部分运行):

shell
1# Option 1 2curl --header "Authorization: Bearer $CI_JOB_TOKEN" \ 3 --url "${CI_API_V4_URL}/job" 4 5# Option 2 6curl --header "JOB-TOKEN: $CI_JOB_TOKEN" \ 7 --url "${CI_API_V4_URL}/job" 8 9# Option 3 10curl --url "${CI_API_V4_URL}/job?job_token=$CI_JOB_TOKEN"

响应示例:

json
1{ 2 "commit": { 3 "author_email": "admin@example.com", 4 "author_name": "Administrator", 5 "created_at": "2015-12-24T16:51:14.000+01:00", 6 "id": "0ff3ae198f8601a285adcf5c0fff204ee6fba5fd", 7 "message": "Test the CI integration.", 8 "short_id": "0ff3ae19", 9 "title": "Test the CI integration." 10 }, 11 "coverage": null, 12 "archived": false, 13 "source": "push", 14 "allow_failure": false, 15 "created_at": "2015-12-24T15:51:21.880Z", 16 "started_at": "2015-12-24T17:54:30.733Z", 17 "finished_at": "2015-12-24T17:54:31.198Z", 18 "erased_at": null, 19 "duration": 0.465, 20 "queued_duration": 0.123, 21 "artifacts_expire_at": "2016-01-23T17:54:31.198Z", 22 "id": 8, 23 "name": "rubocop", 24 "pipeline": { 25 "id": 6, 26 "project_id": 1, 27 "ref": "main", 28 "sha": "0ff3ae198f8601a285adcf5c0fff204ee6fba5fd", 29 "status": "pending" 30 }, 31 "ref": "main", 32 "artifacts": [], 33 "runner": null, 34 "runner_manager": null, 35 "stage": "test", 36 "status": "failed", 37 "failure_reason": "script_failure", 38 "tag": false, 39 "web_url": "https://example.com/foo/bar/-/jobs/8", 40 "project": { 41 "ci_job_token_scope_enabled": false 42 }, 43 "user": { 44 "id": 1, 45 "name": "Administrator", 46 "username": "root", 47 "state": "active", 48 "avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon", 49 "web_url": "http://gitlab.dev/root", 50 "created_at": "2015-12-21T13:14:24.077Z", 51 "bio": null, 52 "location": null, 53 "public_email": "", 54 "skype": "", 55 "linkedin": "", 56 "twitter": "", 57 "website_url": "", 58 "organization": "" 59 } 60}

获取单个作业#

获取项目的单个作业。

plaintext
GET /projects/:id/jobs/:job_id
属性类型必需描述
idinteger/string项目的 ID 或 URL 编码的路径
job_idinteger作业的 ID。
shell
curl --header "PRIVATE-TOKEN: <your_access_token>" \ --url "https://gitlab.example.com/api/v4/projects/1/jobs/8"

响应示例:

json
1{ 2 "commit": { 3 "author_email": "admin@example.com", 4 "author_name": "Administrator", 5 "created_at": "2015-12-24T16:51:14.000+01:00", 6 "id": "0ff3ae198f8601a285adcf5c0fff204ee6fba5fd", 7 "message": "Test the CI integration.", 8 "short_id": "0ff3ae19", 9 "title": "Test the CI integration." 10 }, 11 "coverage": null, 12 "archived": false, 13 "source": "push", 14 "allow_failure": false, 15 "created_at": "2015-12-24T15:51:21.880Z", 16 "started_at": "2015-12-24T17:54:30.733Z", 17 "finished_at": "2015-12-24T17:54:31.198Z", 18 "erased_at": null, 19 "duration": 0.465, 20 "queued_duration": 0.010, 21 "artifacts_expire_at": "2016-01-23T17:54:31.198Z", 22 "tag_list": [ 23 "docker runner", "macos-10.15" 24 ], 25 "id": 8, 26 "name": "rubocop", 27 "pipeline": { 28 "id": 6, 29 "project_id": 1, 30 "ref": "main", 31 "sha": "0ff3ae198f8601a285adcf5c0fff204ee6fba5fd", 32 "status": "pending" 33 }, 34 "ref": "main", 35 "artifacts": [], 36 "runner": null, 37 "runner_manager": null, 38 "stage": "test", 39 "status": "failed", 40 "tag": false, 41 "web_url": "https://example.com/foo/bar/-/jobs/8", 42 "project": { 43 "ci_job_token_scope_enabled": false 44 }, 45 "user": { 46 "id": 1, 47 "name": "Administrator", 48 "username": "root", 49 "state": "active", 50 "avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon", 51 "web_url": "http://gitlab.dev/root", 52 "created_at": "2015-12-21T13:14:24.077Z", 53 "bio": null, 54 "location": null, 55 "public_email": "", 56 "skype": "", 57 "linkedin": "", 58 "twitter": "", 59 "website_url": "", 60 "organization": "" 61 } 62}

获取日志文件#

获取项目特定作业的日志(追踪)。

plaintext
GET /projects/:id/jobs/:job_id/trace
属性类型必需描述
idinteger/string项目的 ID 或 URL 编码的路径
job_idinteger作业的 ID。
shell
curl --location \ --header "PRIVATE-TOKEN: <your_access_token>" \ --url "https://gitlab.example.com/api/v4/projects/1/jobs/8/trace"

可能的响应状态代码:

状态描述
200提供日志文件
404作业未找到或无日志文件

取消作业#

取消项目的单个作业。

plaintext
POST /projects/:id/jobs/:job_id/cancel
属性类型必需描述
idinteger/string项目的 ID 或 URL 编码的路径
job_idinteger作业的 ID。
forceboolean在设置为 true 时,强制取消 处于 canceling 状态的作业。
shell
curl --request POST \ --header "PRIVATE-TOKEN: <your_access_token>" \ --url "https://gitlab.example.com/api/v4/projects/1/jobs/1/cancel"

响应示例:

json
1{ 2 "commit": { 3 "author_email": "admin@example.com", 4 "author_name": "Administrator", 5 "created_at": "2015-12-24T16:51:14.000+01:00", 6 "id": "0ff3ae198f8601a285adcf5c0fff204ee6fba5fd", 7 "message": "Test the CI integration.", 8 "short_id": "0ff3ae19", 9 "title": "Test the CI integration." 10 }, 11 "coverage": null, 12 "archived": false, 13 "source": "push", 14 "allow_failure": false, 15 "created_at": "2016-01-11T10:13:33.506Z", 16 "started_at": "2016-01-11T10:14:09.526Z", 17 "finished_at": null, 18 "erased_at": null, 19 "duration": 8, 20 "queued_duration": 0.010, 21 "id": 1, 22 "name": "rubocop", 23 "ref": "main", 24 "artifacts": [], 25 "runner": null, 26 "runner_manager": null, 27 "stage": "test", 28 "status": "canceled", 29 "tag": false, 30 "web_url": "https://example.com/foo/bar/-/jobs/1", 31 "project": { 32 "ci_job_token_scope_enabled": false 33 }, 34 "user": null 35}

重试作业#

重试项目的单个作业。

plaintext
POST /projects/:id/jobs/:job_id/retry
属性类型必需描述
idinteger/string项目的 ID 或 URL 编码的路径
job_idinteger作业的 ID。
shell
curl --request POST \ --header "PRIVATE-TOKEN: <your_access_token>" \ --url "https://gitlab.example.com/api/v4/projects/1/jobs/1/retry"

响应示例:

json
1{ 2 "commit": { 3 "author_email": "admin@example.com", 4 "author_name": "Administrator", 5 "created_at": "2015-12-24T16:51:14.000+01:00", 6 "id": "0ff3ae198f8601a285adcf5c0fff204ee6fba5fd", 7 "message": "Test the CI integration.", 8 "short_id": "0ff3ae19", 9 "title": "Test the CI integration." 10 }, 11 "coverage": null, 12 "archived": false, 13 "source": "push", 14 "allow_failure": false, 15 "created_at": "2016-01-11T10:13:33.506Z", 16 "started_at": null, 17 "finished_at": null, 18 "erased_at": null, 19 "duration": null, 20 "queued_duration": 0.010, 21 "id": 1, 22 "name": "rubocop", 23 "ref": "main", 24 "artifacts": [], 25 "runner": null, 26 "runner_manager": null, 27 "stage": "test", 28 "status": "pending", 29 "tag": false, 30 "web_url": "https://example.com/foo/bar/-/jobs/1", 31 "project": { 32 "ci_job_token_scope_enabled": false 33 }, 34 "user": null 35}
在极狐GitLab 17.0 之前,此端点不支持触发作业。

擦除作业#

擦除项目的单个作业(删除作业产物和作业日志)。

plaintext
POST /projects/:id/jobs/:job_id/erase

参数:

属性类型必需描述
idinteger/string项目的 ID 或 URL 编码的路径
job_idinteger作业的 ID。

请求示例:

shell
curl --request POST \ --header "PRIVATE-TOKEN: <your_access_token>" \ --url "https://gitlab.example.com/api/v4/projects/1/jobs/1/erase"

响应示例:

json
1{ 2 "commit": { 3 "author_email": "admin@example.com", 4 "author_name": "Administrator", 5 "created_at": "2015-12-24T16:51:14.000+01:00", 6 "id": "0ff3ae198f8601a285adcf5c0fff204ee6fba5fd", 7 "message": "Test the CI integration.", 8 "short_id": "0ff3ae19", 9 "title": "Test the CI integration." 10 }, 11 "coverage": null, 12 "archived": false, 13 "source": "push", 14 "allow_failure": false, 15 "download_url": null, 16 "id": 1, 17 "name": "rubocop", 18 "ref": "main", 19 "artifacts": [], 20 "runner": null, 21 "runner_manager": null, 22 "stage": "test", 23 "created_at": "2016-01-11T10:13:33.506Z", 24 "started_at": "2016-01-11T10:13:33.506Z", 25 "finished_at": "2016-01-11T10:15:10.506Z", 26 "erased_at": "2016-01-11T11:30:19.914Z", 27 "duration": 97.0, 28 "queued_duration": 0.010, 29 "status": "failed", 30 "tag": false, 31 "web_url": "https://example.com/foo/bar/-/jobs/1", 32 "project": { 33 "ci_job_token_scope_enabled": false 34 }, 35 "user": null 36}
您无法通过 API 删除归档的作业,但可以[删除在特定日期之前完成的作业的产物和日志](../administration/cicd/job_artifacts_troubleshooting.md#delete-old-builds-and-artifacts)。

运行作业#

对于处于手动状态的作业,触发一个操作以启动作业。

plaintext
POST /projects/:id/jobs/:job_id/play
属性类型必需描述
idinteger/string项目的 ID 或 URL 编码的路径
job_idinteger作业的 ID。
job_variables_attributesarray of hashes包含作业可用的自定义变量的数组。

请求示例:

shell
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 结构如下:

json
1{ 2 "job_variables_attributes": [ 3 { 4 "key": "TEST_VAR_1", 5 "value": "test1" 6 }, 7 { 8 "key": "TEST_VAR_2", 9 "value": "test2" 10 } 11 ] 12}

响应示例:

json
1{ 2 "commit": { 3 "author_email": "admin@example.com", 4 "author_name": "Administrator", 5 "created_at": "2015-12-24T16:51:14.000+01:00", 6 "id": "0ff3ae198f8601a285adcf5c0fff204ee6fba5fd", 7 "message": "Test the CI integration.", 8 "short_id": "0ff3ae19", 9 "title": "Test the CI integration." 10 }, 11 "coverage": null, 12 "archived": false, 13 "source": "push", 14 "allow_failure": false, 15 "created_at": "2016-01-11T10:13:33.506Z", 16 "started_at": null, 17 "finished_at": null, 18 "erased_at": null, 19 "duration": null, 20 "queued_duration": 0.010, 21 "id": 1, 22 "name": "rubocop", 23 "ref": "main", 24 "artifacts": [], 25 "runner": null, 26 "runner_manager": null, 27 "stage": "test", 28 "status": "pending", 29 "tag": false, 30 "web_url": "https://example.com/foo/bar/-/jobs/1", 31 "project": { 32 "ci_job_token_scope_enabled": false 33 }, 34 "user": null 35}