325.md 28.1 KB
Newer Older
Lab机器人's avatar
readme  
Lab机器人 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465
# 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: <your_access_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: <your_access_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: <your_access_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: <your_access_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: <your_access_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: <your_access_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: <your_access_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: <your_access_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: <your_access_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: <your_access_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: <your_access_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: <your_access_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: <your_access_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: <your_access_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: <your_access_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  } 
```