# Jobs API > 原文:[https://docs.gitlab.com/ee/api/jobs.html](https://docs.gitlab.com/ee/api/jobs.html) * [List project jobs](#list-project-jobs) * [List pipeline jobs](#list-pipeline-jobs) * [List pipeline bridges](#list-pipeline-bridges) * [Get a single job](#get-a-single-job) * [Get job artifacts](#get-job-artifacts) * [Download the artifacts archive](#download-the-artifacts-archive) * [Download a single artifact file by job ID](#download-a-single-artifact-file-by-job-id) * [Download a single artifact file from specific tag or branch](#download-a-single-artifact-file-from-specific-tag-or-branch) * [Get a log file](#get-a-log-file) * [Cancel a job](#cancel-a-job) * [Retry a job](#retry-a-job) * [Erase a job](#erase-a-job) * [Keep artifacts](#keep-artifacts) * [Delete artifacts](#delete-artifacts) * [Play a job](#play-a-job) # Jobs API[](#jobs-api "Permalink") ## List project jobs[](#list-project-jobs "Permalink") 获取项目中的作业列表. 作业按 ID 的降序排列. ``` GET /projects/:id/jobs ``` | Attribute | Type | Required | Description | | --- | --- | --- | --- | | `id` | integer/string | yes | 身份验证用户拥有[的项目的](README.html#namespaced-path-encoding) ID 或[URL 编码路径](README.html#namespaced-path-encoding) . | | `scope` | 字符串**或**字符串数组 | no | 要显示的工作范围. 以下一项或多项: `created` , `pending` , `running` , `failed` , `success` , `canceled` , `skipped`或`manual` . 如果未提供`scope`则返回所有作业. | ``` curl --globoff --header "PRIVATE-TOKEN: " "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, "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", "duration": 0.173, "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", "id": 7, "name": "teaspoon", "pipeline": { "id": 6, "ref": "master", "sha": "0ff3ae198f8601a285adcf5c0fff204ee6fba5fd", "status": "pending" }, "ref": "master", "artifacts": [], "runner": null, "stage": "test", "status": "failed", "tag": false, "web_url": "https://example.com/foo/bar/-/jobs/7", "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": "", "skype": "", "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, "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", "duration": 0.192, "artifacts_expire_at": "2016-01-23T17:54:24.921Z", "id": 6, "name": "rspec:other", "pipeline": { "id": 6, "ref": "master", "sha": "0ff3ae198f8601a285adcf5c0fff204ee6fba5fd", "status": "pending" }, "ref": "master", "artifacts": [], "runner": null, "stage": "test", "status": "failed", "tag": false, "web_url": "https://example.com/foo/bar/-/jobs/6", "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": "", "skype": "", "linkedin": "", "twitter": "", "website_url": "", "organization": "" } } ] ``` ## List pipeline jobs[](#list-pipeline-jobs "Permalink") 获取管道的作业列表. ``` GET /projects/:id/pipelines/:pipeline_id/jobs ``` | Attribute | Type | Required | Description | | --- | --- | --- | --- | | `id` | integer/string | yes | 身份验证用户拥有[的项目的](README.html#namespaced-path-encoding) ID 或[URL 编码路径](README.html#namespaced-path-encoding) . | | `pipeline_id` | integer | yes | 管道的 ID. | | `scope` | 字符串**或**字符串数组 | no | 要显示的工作范围. 以下一项或多项: `created` , `pending` , `running` , `failed` , `success` , `canceled` , `skipped`或`manual` . 如果未提供`scope`则返回所有作业. | ``` curl --header "PRIVATE-TOKEN: " "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, "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", "duration": 0.192, "artifacts_expire_at": "2016-01-23T17:54:24.921Z", "id": 6, "name": "rspec:other", "pipeline": { "id": 6, "ref": "master", "sha": "0ff3ae198f8601a285adcf5c0fff204ee6fba5fd", "status": "pending" }, "ref": "master", "artifacts": [], "runner": null, "stage": "test", "status": "failed", "tag": false, "web_url": "https://example.com/foo/bar/-/jobs/6", "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": "", "skype": "", "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, "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", "duration": 0.173, "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", "id": 7, "name": "teaspoon", "pipeline": { "id": 6, "ref": "master", "sha": "0ff3ae198f8601a285adcf5c0fff204ee6fba5fd", "status": "pending" }, "ref": "master", "artifacts": [], "runner": null, "stage": "test", "status": "failed", "tag": false, "web_url": "https://example.com/foo/bar/-/jobs/7", "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": "", "skype": "", "linkedin": "", "twitter": "", "website_url": "", "organization": "" } } ] ``` 从 GitLab 13.2 开始,此端点[将返回任何管道(](pipelines.html#single-pipeline-requests)包括[子管道)的数据](../ci/parent_child_pipelines.html) . ## List pipeline bridges[](#list-pipeline-bridges "Permalink") 获取管道的桥作业列表. ``` GET /projects/:id/pipelines/:pipeline_id/bridges ``` | Attribute | Type | Required | Description | | --- | --- | --- | --- | | `id` | integer/string | yes | 身份验证用户拥有[的项目的](README.html#namespaced-path-encoding) ID 或[URL 编码路径](README.html#namespaced-path-encoding) . | | `pipeline_id` | integer | yes | 管道的 ID. | | `scope` | 字符串**或**字符串数组 | no | 要显示的工作范围. 以下一项或多项: `created` , `pending` , `running` , `failed` , `success` , `canceled` , `skipped`或`manual` . 如果未提供`scope`则返回所有作业. | ``` curl --header "PRIVATE-TOKEN: " '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, "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", "duration": 240, "id": 7, "name": "teaspoon", "pipeline": { "id": 6, "ref": "master", "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": "master", "stage": "test", "status": "pending", "tag": false, "web_url": "https://example.com/foo/bar/-/jobs/7", "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": "", "skype": "", "linkedin": "", "twitter": "", "website_url": "", "organization": "" }, "downstream_pipeline": { "id": 5, "sha": "f62a4b2fb89754372a346f24659212eb8da13601", "ref": "master", "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 a single job[](#get-a-single-job "Permalink") 获得项目的一份工作 ``` GET /projects/:id/jobs/:job_id ``` | Attribute | Type | Required | Description | | --- | --- | --- | --- | | `id` | integer/string | yes | 身份验证用户拥有[的项目的](README.html#namespaced-path-encoding) ID 或[URL 编码路径](README.html#namespaced-path-encoding) . | | `job_id` | integer | yes | 工作 ID. | ``` curl --header "PRIVATE-TOKEN: " "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, "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", "duration": 0.465, "artifacts_expire_at": "2016-01-23T17:54:31.198Z", "id": 8, "name": "rubocop", "pipeline": { "id": 6, "ref": "master", "sha": "0ff3ae198f8601a285adcf5c0fff204ee6fba5fd", "status": "pending" }, "ref": "master", "artifacts": [], "runner": null, "stage": "test", "status": "failed", "tag": false, "web_url": "https://example.com/foo/bar/-/jobs/8", "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": "", "skype": "", "linkedin": "", "twitter": "", "website_url": "", "organization": "" } } ``` ## Get job artifacts[](#get-job-artifacts "Permalink") 版本历史 **注意事项** : * 在 GitLab 8.5 中[引入](https://gitlab.com/gitlab-org/gitlab-foss/-/merge_requests/2893) . * 在[GitLab Premium](https://about.gitlab.com/pricing/) 9.5 中[引入了](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/2346)在工件下载 API 中使用`CI_JOB_TOKEN` . 获取项目的工件压缩文件存档. ``` GET /projects/:id/jobs/:job_id/artifacts ``` | Attribute | Type | Required | Description | | --- | --- | --- | --- | | `id` | integer/string | yes | 身份验证用户拥有[的项目的](README.html#namespaced-path-encoding) ID 或[URL 编码路径](README.html#namespaced-path-encoding) . | | `job_id` | integer | yes | 工作 ID. | | `job_token` | string | no | 与多项目管道的[触发器](../ci/triggers/README.html#when-a-pipeline-depends-on-the-artifacts-of-another-pipeline-premium)一起使用. 它只能在`.gitlab-ci.yml`内部调用. 其值始终`$CI_JOB_TOKEN` . | 使用`PRIVATE-TOKEN`标头的示例请求: ``` curl --output artifacts.zip --header "PRIVATE-TOKEN: " "https://gitlab.example.com/api/v4/projects/1/jobs/42/artifacts" ``` 要在`.gitlab-ci.yml`中的[`script`定义中](../ci/yaml/README.html#script)使用它 ,您可以使用以下任一方法: * GitLab 提供的`CI_JOB_TOKEN`变量的`JOB-TOKEN`标头. 例如,以下作业将下载 ID 为`42`的作业工件. 注意,该命令被缠绕成单引号,因为它含有一个冒号( `:` ): ``` artifact_download: stage: test script: - 'curl --location --output artifacts.zip --header "JOB-TOKEN: $CI_JOB_TOKEN" "https://gitlab.example.com/api/v4/projects/1/jobs/42/artifacts"' ``` * 或带有 GitLab 提供的`CI_JOB_TOKEN`变量的`job_token`属性. 例如,以下作业将下载 ID 为`42`的作业的工件: ``` artifact_download: stage: test script: - 'curl --location --output artifacts.zip "https://gitlab.example.com/api/v4/projects/1/jobs/42/artifacts?job_token=$CI_JOB_TOKEN"' ``` 可能的响应状态代码: | Status | Description | | --- | --- | | 200 | Serves the artifacts file. | | 404 | 找不到构建或没有工件. | ## Download the artifacts archive[](#download-the-artifacts-archive "Permalink") 版本历史 **注意事项** : * 在 GitLab 8.10 中[引入](https://gitlab.com/gitlab-org/gitlab-foss/-/merge_requests/5347) . * 在[GitLab Premium](https://about.gitlab.com/pricing/) 9.5 中[引入了](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/2346)在工件下载 API 中使用`CI_JOB_TOKEN` . 如果作业成功完成,请从最新成功的管道中下载给定参考名称和作业的工件压缩存档. 这与[获取作业的工件相同](#get-job-artifacts) ,但是通过定义作业的名称而不是其 ID. ``` GET /projects/:id/jobs/artifacts/:ref_name/download?job=name ``` Parameters | Attribute | Type | Required | Description | | --- | --- | --- | --- | | `id` | integer/string | yes | 身份验证用户拥有[的项目的](README.html#namespaced-path-encoding) ID 或[URL 编码路径](README.html#namespaced-path-encoding) . | | `ref_name` | string | yes | 存储库中的分支或标记名称. 不支持 HEAD 或 SHA 引用. | | `job` | string | yes | 工作名称. | | `job_token` | string | no | 与多项目管道的[触发器](../ci/triggers/README.html#when-a-pipeline-depends-on-the-artifacts-of-another-pipeline-premium)一起使用. 它只能在`.gitlab-ci.yml`内部调用. 其值始终`$CI_JOB_TOKEN` . | 使用`PRIVATE-TOKEN`标头的示例请求: ``` curl --header "PRIVATE-TOKEN: " "https://gitlab.example.com/api/v4/projects/1/jobs/artifacts/master/download?job=test" ``` 要在`.gitlab-ci.yml`中的[`script`定义中](../ci/yaml/README.html#script)使用它 ,您可以使用以下任一方法: * GitLab 提供的`CI_JOB_TOKEN`变量的`JOB-TOKEN`标头. 例如,以下作业将下载`master`分支的`test`作业的工件. 注意,该命令被缠绕成单引号,因为它含有一个冒号( `:` ): ``` artifact_download: stage: test script: - 'curl --location --output artifacts.zip --header "JOB-TOKEN: $CI_JOB_TOKEN" "https://gitlab.example.com/api/v4/projects/$CI_PROJECT_ID/jobs/artifacts/master/download?job=test"' ``` * 或带有 GitLab 提供的`CI_JOB_TOKEN`变量的`job_token`属性. 例如,以下作业将下载`master`分支的`test`作业的工件: ``` artifact_download: stage: test script: - 'curl --location --output artifacts.zip "https://gitlab.example.com/api/v4/projects/$CI_PROJECT_ID/jobs/artifacts/master/download?job=test&job_token=$CI_JOB_TOKEN"' ``` 可能的响应状态代码: | Status | Description | | --- | --- | | 200 | 服务工件文件. | | 404 | 找不到构建或没有工件. | ## Download a single artifact file by job ID[](#download-a-single-artifact-file-by-job-id "Permalink") 在 GitLab 10.0 中引入 从作业的工件压缩文件中以指定的 ID 下载作业中的单个工件文件. 从存档中提取文件,并将其流式传输到客户端. ``` GET /projects/:id/jobs/:job_id/artifacts/*artifact_path ``` Parameters | Attribute | Type | Required | Description | | --- | --- | --- | --- | | `id` | integer/string | yes | 身份验证用户拥有[的项目的](README.html#namespaced-path-encoding) ID 或[URL 编码路径](README.html#namespaced-path-encoding) . | | `job_id` | integer | yes | 唯一的作业标识符. | | `artifact_path` | string | yes | 工件存档内文件的路径. | 请求示例: ``` curl --location --header "PRIVATE-TOKEN: " "https://gitlab.example.com/api/v4/projects/1/jobs/5/artifacts/some/release/file.pdf" ``` 可能的响应状态代码: | Status | Description | | --- | --- | | 200 | 发送单个工件文件 | | 400 | 提供的路径无效 | | 404 | 找不到版本或没有文件/工件 | ## Download a single artifact file from specific tag or branch[](#download-a-single-artifact-file-from-specific-tag-or-branch "Permalink") 在 GitLab 11.5 中[引入](https://gitlab.com/gitlab-org/gitlab-foss/-/merge_requests/23538) . 从作业的工件存档中为给定的参考名称下载最新成功管道的特定作业的单个工件文件. 从存档中提取文件,并将其流式传输到客户端. ``` GET /projects/:id/jobs/artifacts/:ref_name/raw/*artifact_path?job=name ``` Parameters: | Attribute | Type | Required | Description | | --- | --- | --- | --- | | `id` | integer/string | yes | 身份验证用户拥有[的项目的](README.html#namespaced-path-encoding) ID 或[URL 编码路径](README.html#namespaced-path-encoding) . | | `ref_name` | string | yes | 存储库中的分支或标记名称. 不支持 HEAD 或 SHA 引用. | | `artifact_path` | string | yes | 工件存档内文件的路径. | | `job` | string | yes | 工作名称. | 请求示例: ``` curl --location --header "PRIVATE-TOKEN: " "https://gitlab.example.com/api/v4/projects/1/jobs/artifacts/master/raw/some/release/file.pdf?job=pdf" ``` 可能的响应状态代码: | Status | Description | | --- | --- | | 200 | 发送单个工件文件 | | 400 | 提供的路径无效 | | 404 | 找不到版本或没有文件/工件 | ## Get a log file[](#get-a-log-file "Permalink") 获取项目的特定作业的日志(跟踪): ``` GET /projects/:id/jobs/:job_id/trace ``` | Attribute | Type | Required | Description | | --- | --- | --- | --- | | `id` | integer/string | yes | 身份验证用户拥有[的项目的](README.html#namespaced-path-encoding) ID 或[URL 编码路径](README.html#namespaced-path-encoding) . | | `job_id` | integer | yes | 工作 ID. | ``` curl --location --header "PRIVATE-TOKEN: " "https://gitlab.example.com/api/v4/projects/1/jobs/8/trace" ``` 可能的响应状态代码: | Status | Description | | --- | --- | | 200 | 服务日志文件 | | 404 | 找不到作业或没有日志文件 | ## Cancel a job[](#cancel-a-job "Permalink") 取消项目的一项工作 ``` POST /projects/:id/jobs/:job_id/cancel ``` | Attribute | Type | Required | Description | | --- | --- | --- | --- | | `id` | integer/string | yes | 身份验证用户拥有[的项目的](README.html#namespaced-path-encoding) ID 或[URL 编码路径](README.html#namespaced-path-encoding) . | | `job_id` | integer | yes | 工作 ID. | ``` curl --request POST --header "PRIVATE-TOKEN: " "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, "allow_failure": false, "created_at": "2016-01-11T10:13:33.506Z", "started_at": "2016-01-11T10:14:09.526Z", "finished_at": null, "duration": 8, "id": 42, "name": "rubocop", "ref": "master", "artifacts": [], "runner": null, "stage": "test", "status": "canceled", "tag": false, "web_url": "https://example.com/foo/bar/-/jobs/42", "user": null } ``` ## Retry a job[](#retry-a-job "Permalink") 重试项目的一项工作 ``` POST /projects/:id/jobs/:job_id/retry ``` | Attribute | Type | Required | Description | | --- | --- | --- | --- | | `id` | integer/string | yes | 身份验证用户拥有[的项目的](README.html#namespaced-path-encoding) ID 或[URL 编码路径](README.html#namespaced-path-encoding) . | | `job_id` | integer | yes | 工作 ID. | ``` curl --request POST --header "PRIVATE-TOKEN: " "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, "allow_failure": false, "created_at": "2016-01-11T10:13:33.506Z", "started_at": null, "finished_at": null, "duration": null, "id": 42, "name": "rubocop", "ref": "master", "artifacts": [], "runner": null, "stage": "test", "status": "pending", "tag": false, "web_url": "https://example.com/foo/bar/-/jobs/42", "user": null } ``` ## Erase a job[](#erase-a-job "Permalink") 擦除项目的单个作业(删除作业工件和作业日志) ``` POST /projects/:id/jobs/:job_id/erase ``` Parameters | Attribute | Type | Required | Description | | --- | --- | --- | --- | | `id` | integer/string | yes | 身份验证用户拥有[的项目的](README.html#namespaced-path-encoding) ID 或[URL 编码路径](README.html#namespaced-path-encoding) . | | `job_id` | integer | yes | 工作 ID. | Example of request ``` curl --request POST --header "PRIVATE-TOKEN: " "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, "allow_failure": false, "download_url": null, "id": 42, "name": "rubocop", "ref": "master", "artifacts": [], "runner": 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", "duration": 97.0, "status": "failed", "tag": false, "web_url": "https://example.com/foo/bar/-/jobs/42", "user": null } ``` ## Keep artifacts[](#keep-artifacts "Permalink") 设置过期时,防止删除工件. ``` POST /projects/:id/jobs/:job_id/artifacts/keep ``` Parameters | Attribute | Type | Required | Description | | --- | --- | --- | --- | | `id` | integer/string | yes | 身份验证用户拥有[的项目的](README.html#namespaced-path-encoding) ID 或[URL 编码路径](README.html#namespaced-path-encoding) . | | `job_id` | integer | yes | 工作 ID. | 请求示例: ``` curl --request POST --header "PRIVATE-TOKEN: " "https://gitlab.example.com/api/v4/projects/1/jobs/1/artifacts/keep" ``` 响应示例: ``` { "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, "allow_failure": false, "download_url": null, "id": 42, "name": "rubocop", "ref": "master", "artifacts": [], "runner": 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", "duration": 97.0, "status": "failed", "tag": false, "web_url": "https://example.com/foo/bar/-/jobs/42", "user": null } ``` ## Delete artifacts[](#delete-artifacts "Permalink") 在 GitLab 11.9 中[引入](https://gitlab.com/gitlab-org/gitlab-foss/-/merge_requests/25522) . 删除作业的工件. ``` DELETE /projects/:id/jobs/:job_id/artifacts ``` | Attribute | Type | Required | Description | | --- | --- | --- | --- | | `id` | integer/string | yes | 项目的 ID 或[URL 编码的路径](README.html#namespaced-path-encoding) | | `job_id` | integer | yes | 工作 ID. | 请求示例: ``` curl --request DELETE --header "PRIVATE-TOKEN: " "https://gitlab.example.com/api/v4/projects/1/jobs/1/artifacts" ``` **注意:**至少需要具有维护者角色才能删除工件. 如果工件被成功删除,则返回状态为`204 No Content`的响应. ## Play a job[](#play-a-job "Permalink") 触发手动操作以开始作业. ``` POST /projects/:id/jobs/:job_id/play ``` | Attribute | Type | Required | Description | | --- | --- | --- | --- | | `id` | integer/string | yes | 身份验证用户拥有[的项目的](README.html#namespaced-path-encoding) ID 或[URL 编码路径](README.html#namespaced-path-encoding) . | | `job_id` | integer | yes | 工作 ID. | ``` curl --request POST --header "PRIVATE-TOKEN: " "https://gitlab.example.com/api/v4/projects/1/jobs/1/play" ``` 回应范例 ``` { "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, "allow_failure": false, "created_at": "2016-01-11T10:13:33.506Z", "started_at": null, "finished_at": null, "duration": null, "id": 42, "name": "rubocop", "ref": "master", "artifacts": [], "runner": null, "stage": "test", "status": "started", "tag": false, "web_url": "https://example.com/foo/bar/-/jobs/42", "user": null } ```