2017-08-17 22:00:37 +05:30
# Jobs API
## List project jobs
2020-01-01 13:55:28 +05:30
Get a list of jobs in a project. Jobs are sorted in descending order of their IDs.
2017-08-17 22:00:37 +05:30
2020-04-08 14:13:33 +05:30
```plaintext
2017-08-17 22:00:37 +05:30
GET /projects/:id/jobs
```
2019-02-15 15:39:39 +05:30
| Attribute | Type | Required | Description |
|-----------|--------------------------------|----------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
2019-07-07 11:18:12 +05:30
| `id` | integer/string | yes | ID or [URL-encoded path of the project ](README.md#namespaced-path-encoding ) owned by the authenticated user. |
2019-02-15 15:39:39 +05:30
| `scope` | string **or** array of strings | no | Scope of jobs to show. Either one of or an array of the following: `created` , `pending` , `running` , `failed` , `success` , `canceled` , `skipped` , or `manual` . All jobs are returned if `scope` is not provided. |
2017-08-17 22:00:37 +05:30
2020-03-13 15:44:24 +05:30
```shell
2019-09-30 21:07:59 +05:30
curl --globoff --header "PRIVATE-TOKEN: < your_access_token > " 'https://gitlab.example.com/api/v4/projects/1/jobs?scope[]=pending& scope[]=running'
2017-08-17 22:00:37 +05:30
```
Example of response
```json
[
{
"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,
2019-09-04 21:01:54 +05:30
"allow_failure": false,
2020-01-01 13:55:28 +05:30
"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",
2017-08-17 22:00:37 +05:30
"pipeline": {
"id": 6,
"ref": "master",
"sha": "0ff3ae198f8601a285adcf5c0fff204ee6fba5fd",
"status": "pending"
},
"ref": "master",
2018-11-20 20:47:30 +05:30
"artifacts": [],
2017-08-17 22:00:37 +05:30
"runner": null,
"stage": "test",
"status": "failed",
"tag": false,
2020-01-01 13:55:28 +05:30
"web_url": "https://example.com/foo/bar/-/jobs/7",
2017-08-17 22:00:37 +05:30
"user": {
"id": 1,
"name": "Administrator",
"username": "root",
2018-12-05 23:21:45 +05:30
"state": "active",
"avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80& d=identicon",
2017-08-17 22:00:37 +05:30
"web_url": "http://gitlab.dev/root",
2018-12-05 23:21:45 +05:30
"created_at": "2015-12-21T13:14:24.077Z",
"bio": null,
"location": null,
"public_email": "",
"skype": "",
"linkedin": "",
"twitter": "",
"website_url": "",
"organization": ""
2017-08-17 22:00:37 +05:30
}
},
{
"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,
2019-09-04 21:01:54 +05:30
"allow_failure": false,
2020-01-01 13:55:28 +05:30
"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",
2017-08-17 22:00:37 +05:30
"pipeline": {
"id": 6,
"ref": "master",
"sha": "0ff3ae198f8601a285adcf5c0fff204ee6fba5fd",
"status": "pending"
},
"ref": "master",
2018-11-20 20:47:30 +05:30
"artifacts": [],
2017-08-17 22:00:37 +05:30
"runner": null,
"stage": "test",
"status": "failed",
"tag": false,
2020-01-01 13:55:28 +05:30
"web_url": "https://example.com/foo/bar/-/jobs/6",
2017-08-17 22:00:37 +05:30
"user": {
"id": 1,
"name": "Administrator",
"username": "root",
2018-12-05 23:21:45 +05:30
"state": "active",
"avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80& d=identicon",
2017-08-17 22:00:37 +05:30
"web_url": "http://gitlab.dev/root",
2018-12-05 23:21:45 +05:30
"created_at": "2015-12-21T13:14:24.077Z",
"bio": null,
"location": null,
"public_email": "",
"skype": "",
"linkedin": "",
"twitter": "",
"website_url": "",
"organization": ""
2017-08-17 22:00:37 +05:30
}
}
]
```
## List pipeline jobs
Get a list of jobs for a pipeline.
2020-04-08 14:13:33 +05:30
```plaintext
2017-08-17 22:00:37 +05:30
GET /projects/:id/pipelines/:pipeline_id/jobs
```
2019-02-15 15:39:39 +05:30
| Attribute | Type | Required | Description |
|---------------|--------------------------------|----------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
2019-07-07 11:18:12 +05:30
| `id` | integer/string | yes | ID or [URL-encoded path of the project ](README.md#namespaced-path-encoding ) owned by the authenticated user. |
| `pipeline_id` | integer | yes | ID of a pipeline. |
2019-02-15 15:39:39 +05:30
| `scope` | string **or** array of strings | no | Scope of jobs to show. Either one of or an array of the following: `created` , `pending` , `running` , `failed` , `success` , `canceled` , `skipped` , or `manual` . All jobs are returned if `scope` is not provided. |
2017-08-17 22:00:37 +05:30
2020-03-13 15:44:24 +05:30
```shell
2019-02-15 15:39:39 +05:30
curl --header "PRIVATE-TOKEN: < your_access_token > " 'https://gitlab.example.com/api/v4/projects/1/pipelines/6/jobs?scope[]=pending& scope[]=running'
2017-08-17 22:00:37 +05:30
```
Example of response
```json
[
{
"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,
2019-09-04 21:01:54 +05:30
"allow_failure": false,
2018-11-08 19:23:39 +05:30
"created_at": "2015-12-24T15:51:21.727Z",
2018-12-05 23:21:45 +05:30
"started_at": "2015-12-24T17:54:24.729Z",
2018-11-08 19:23:39 +05:30
"finished_at": "2015-12-24T17:54:24.921Z",
2018-12-05 23:21:45 +05:30
"duration": 0.192,
2018-11-18 11:00:15 +05:30
"artifacts_expire_at": "2016-01-23T17:54:24.921Z",
2018-11-08 19:23:39 +05:30
"id": 6,
"name": "rspec:other",
2017-08-17 22:00:37 +05:30
"pipeline": {
"id": 6,
"ref": "master",
"sha": "0ff3ae198f8601a285adcf5c0fff204ee6fba5fd",
"status": "pending"
},
"ref": "master",
2018-11-20 20:47:30 +05:30
"artifacts": [],
2017-08-17 22:00:37 +05:30
"runner": null,
"stage": "test",
"status": "failed",
"tag": false,
2018-11-18 11:00:15 +05:30
"web_url": "https://example.com/foo/bar/-/jobs/6",
2017-08-17 22:00:37 +05:30
"user": {
"id": 1,
"name": "Administrator",
"username": "root",
2018-12-05 23:21:45 +05:30
"state": "active",
"avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80& d=identicon",
2017-08-17 22:00:37 +05:30
"web_url": "http://gitlab.dev/root",
2018-12-05 23:21:45 +05:30
"created_at": "2015-12-21T13:14:24.077Z",
"bio": null,
"location": null,
"public_email": "",
"skype": "",
"linkedin": "",
"twitter": "",
"website_url": "",
"organization": ""
2017-08-17 22:00:37 +05:30
}
},
{
"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,
2019-09-04 21:01:54 +05:30
"allow_failure": false,
2018-11-08 19:23:39 +05:30
"created_at": "2015-12-24T15:51:21.802Z",
2018-12-05 23:21:45 +05:30
"started_at": "2015-12-24T17:54:27.722Z",
"finished_at": "2015-12-24T17:54:27.895Z",
"duration": 0.173,
2018-11-08 19:23:39 +05:30
"artifacts_file": {
"filename": "artifacts.zip",
"size": 1000
},
2018-11-20 20:47:30 +05:30
"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"}
],
2018-11-18 11:00:15 +05:30
"artifacts_expire_at": "2016-01-23T17:54:27.895Z",
2018-11-08 19:23:39 +05:30
"id": 7,
"name": "teaspoon",
2017-08-17 22:00:37 +05:30
"pipeline": {
"id": 6,
"ref": "master",
"sha": "0ff3ae198f8601a285adcf5c0fff204ee6fba5fd",
"status": "pending"
},
"ref": "master",
2018-11-20 20:47:30 +05:30
"artifacts": [],
2017-08-17 22:00:37 +05:30
"runner": null,
"stage": "test",
"status": "failed",
"tag": false,
2018-11-18 11:00:15 +05:30
"web_url": "https://example.com/foo/bar/-/jobs/7",
2017-08-17 22:00:37 +05:30
"user": {
"id": 1,
"name": "Administrator",
"username": "root",
2018-12-05 23:21:45 +05:30
"state": "active",
"avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80& d=identicon",
2017-08-17 22:00:37 +05:30
"web_url": "http://gitlab.dev/root",
2018-12-05 23:21:45 +05:30
"created_at": "2015-12-21T13:14:24.077Z",
"bio": null,
"location": null,
"public_email": "",
"skype": "",
"linkedin": "",
"twitter": "",
"website_url": "",
"organization": ""
2017-08-17 22:00:37 +05:30
}
}
]
```
## Get a single job
Get a single job of a project
2020-04-08 14:13:33 +05:30
```plaintext
2017-08-17 22:00:37 +05:30
GET /projects/:id/jobs/:job_id
```
2019-02-15 15:39:39 +05:30
| Attribute | Type | Required | Description |
|-----------|----------------|----------|------------------------------------------------------------------------------------------------------------------|
2019-07-07 11:18:12 +05:30
| `id` | integer/string | yes | ID or [URL-encoded path of the project ](README.md#namespaced-path-encoding ) owned by the authenticated user. |
| `job_id` | integer | yes | ID of a job. |
2017-08-17 22:00:37 +05:30
2020-03-13 15:44:24 +05:30
```shell
2019-02-15 15:39:39 +05:30
curl --header "PRIVATE-TOKEN: < your_access_token > " "https://gitlab.example.com/api/v4/projects/1/jobs/8"
2017-08-17 22:00:37 +05:30
```
Example of response
```json
{
"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,
2019-09-04 21:01:54 +05:30
"allow_failure": false,
2017-08-17 22:00:37 +05:30
"created_at": "2015-12-24T15:51:21.880Z",
2018-12-05 23:21:45 +05:30
"started_at": "2015-12-24T17:54:30.733Z",
2017-08-17 22:00:37 +05:30
"finished_at": "2015-12-24T17:54:31.198Z",
2018-12-05 23:21:45 +05:30
"duration": 0.465,
2018-11-08 19:23:39 +05:30
"artifacts_expire_at": "2016-01-23T17:54:31.198Z",
2017-08-17 22:00:37 +05:30
"id": 8,
"name": "rubocop",
"pipeline": {
"id": 6,
"ref": "master",
"sha": "0ff3ae198f8601a285adcf5c0fff204ee6fba5fd",
"status": "pending"
},
"ref": "master",
2018-11-20 20:47:30 +05:30
"artifacts": [],
2017-08-17 22:00:37 +05:30
"runner": null,
"stage": "test",
"status": "failed",
"tag": false,
2018-11-18 11:00:15 +05:30
"web_url": "https://example.com/foo/bar/-/jobs/8",
2017-08-17 22:00:37 +05:30
"user": {
"id": 1,
"name": "Administrator",
"username": "root",
2018-12-05 23:21:45 +05:30
"state": "active",
"avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80& d=identicon",
2017-08-17 22:00:37 +05:30
"web_url": "http://gitlab.dev/root",
2018-12-05 23:21:45 +05:30
"created_at": "2015-12-21T13:14:24.077Z",
"bio": null,
"location": null,
"public_email": "",
"skype": "",
"linkedin": "",
"twitter": "",
"website_url": "",
"organization": ""
2017-08-17 22:00:37 +05:30
}
}
```
## Get job artifacts
2018-05-09 12:01:36 +05:30
> **Notes**:
2018-12-05 23:21:45 +05:30
>
2020-05-24 23:13:21 +05:30
> - [Introduced](https://gitlab.com/gitlab-org/gitlab-foss/-/merge_requests/2893) in GitLab 8.5.
2020-04-22 19:07:51 +05:30
> - The use of `CI_JOB_TOKEN` in the artifacts download API was [introduced](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/2346)
> in [GitLab Premium](https://about.gitlab.com/pricing/) 9.5.
2017-08-17 22:00:37 +05:30
2019-09-04 21:01:54 +05:30
Get the job's artifacts zipped archive of a project.
2017-08-17 22:00:37 +05:30
2020-04-08 14:13:33 +05:30
```plaintext
2017-08-17 22:00:37 +05:30
GET /projects/:id/jobs/:job_id/artifacts
```
2019-09-04 21:01:54 +05:30
| Attribute | Type | Required | Description |
|-------------|----------------|----------|-------------------------------------------------------------------------------------------------------------------------------------------------|
| `id` | integer/string | yes | ID or [URL-encoded path of the project ](README.md#namespaced-path-encoding ) owned by the authenticated user. |
| `job_id` | integer | yes | ID of a job. |
2020-04-22 19:07:51 +05:30
| `job_token` ** (PREMIUM)** | string | no | To be used with [triggers ](../ci/triggers/README.md#when-a-pipeline-depends-on-the-artifacts-of-another-pipeline-premium ) for multi-project pipelines. It should be invoked only inside `.gitlab-ci.yml` . Its value is always `$CI_JOB_TOKEN` . |
2017-08-17 22:00:37 +05:30
2019-09-04 21:01:54 +05:30
Example request using the `PRIVATE-TOKEN` header:
2018-05-09 12:01:36 +05:30
2020-03-13 15:44:24 +05:30
```shell
2019-09-04 21:01:54 +05:30
curl --output artifacts.zip --header "PRIVATE-TOKEN: < your_access_token > " "https://gitlab.example.com/api/v4/projects/1/jobs/42/artifacts"
2017-08-17 22:00:37 +05:30
```
2019-09-04 21:01:54 +05:30
To use this in a [`script` definition ](../ci/yaml/README.md#script ) inside
2019-09-30 21:07:59 +05:30
`.gitlab-ci.yml` ** (PREMIUM)**, you can use either:
2019-09-04 21:01:54 +05:30
- The `JOB-TOKEN` header with the GitLab-provided `CI_JOB_TOKEN` variable.
For example, the following job will download the artifacts of the job with ID
`42` . Note that the command is wrapped into single quotes since it contains a
colon (`:`):
```yaml
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"'
```
- Or the `job_token` attribute with the GitLab-provided `CI_JOB_TOKEN` variable.
For example, the following job will download the artifacts of the job with ID `42` :
```yaml
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"'
```
2019-02-15 15:39:39 +05:30
Possible response status codes:
2017-08-17 22:00:37 +05:30
| Status | Description |
|-----------|---------------------------------|
2019-09-04 21:01:54 +05:30
| 200 | Serves the artifacts file. |
| 404 | Build not found or no artifacts.|
2017-08-17 22:00:37 +05:30
2018-03-17 18:26:18 +05:30
## Download the artifacts archive
2017-08-17 22:00:37 +05:30
2018-05-09 12:01:36 +05:30
> **Notes**:
2018-12-05 23:21:45 +05:30
>
2020-05-24 23:13:21 +05:30
> - [Introduced](https://gitlab.com/gitlab-org/gitlab-foss/-/merge_requests/5347) in GitLab 8.10.
2020-04-22 19:07:51 +05:30
> - The use of `CI_JOB_TOKEN` in the artifacts download API was [introduced](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/2346)
> in [GitLab Premium](https://about.gitlab.com/pricing/) 9.5.
2017-08-17 22:00:37 +05:30
2019-09-30 21:07:59 +05:30
Download the artifacts zipped archive from the latest successful pipeline for
the given reference name and job, provided the job finished successfully. This
is the same as [getting the job's artifacts ](#get-job-artifacts ), but by
defining the job's name instead of its ID.
2017-08-17 22:00:37 +05:30
2020-04-08 14:13:33 +05:30
```plaintext
2017-08-17 22:00:37 +05:30
GET /projects/:id/jobs/artifacts/:ref_name/download?job=name
```
Parameters
2019-09-04 21:01:54 +05:30
| Attribute | Type | Required | Description |
|-------------|----------------|----------|-------------------------------------------------------------------------------------------------------------------------------------------------|
| `id` | integer/string | yes | ID or [URL-encoded path of the project ](README.md#namespaced-path-encoding ) owned by the authenticated user. |
| `ref_name` | string | yes | Branch or tag name in repository. HEAD or SHA references are not supported. |
| `job` | string | yes | The name of the job. |
2020-04-22 19:07:51 +05:30
| `job_token` ** (PREMIUM)** | string | no | To be used with [triggers ](../ci/triggers/README.md#when-a-pipeline-depends-on-the-artifacts-of-another-pipeline-premium ) for multi-project pipelines. It should be invoked only inside `.gitlab-ci.yml` . Its value is always `$CI_JOB_TOKEN` . |
2017-08-17 22:00:37 +05:30
2019-09-04 21:01:54 +05:30
Example request using the `PRIVATE-TOKEN` header:
2017-08-17 22:00:37 +05:30
2020-03-13 15:44:24 +05:30
```shell
2019-02-15 15:39:39 +05:30
curl --header "PRIVATE-TOKEN: < your_access_token > " "https://gitlab.example.com/api/v4/projects/1/jobs/artifacts/master/download?job=test"
2017-08-17 22:00:37 +05:30
```
2019-09-04 21:01:54 +05:30
To use this in a [`script` definition ](../ci/yaml/README.md#script ) inside
2019-09-30 21:07:59 +05:30
`.gitlab-ci.yml` ** (PREMIUM)**, you can use either:
2019-09-04 21:01:54 +05:30
- The `JOB-TOKEN` header with the GitLab-provided `CI_JOB_TOKEN` variable.
For example, the following job will download the artifacts of the `test` job
of the `master` branch. Note that the command is wrapped into single quotes
since it contains a colon (`:`):
```yaml
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"'
```
- Or the `job_token` attribute with the GitLab-provided `CI_JOB_TOKEN` variable.
For example, the following job will download the artifacts of the `test` job
of the `master` branch:
```yaml
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"'
```
2019-02-15 15:39:39 +05:30
Possible response status codes:
2017-08-17 22:00:37 +05:30
| Status | Description |
|-----------|---------------------------------|
2019-09-04 21:01:54 +05:30
| 200 | Serves the artifacts file. |
| 404 | Build not found or no artifacts.|
2017-08-17 22:00:37 +05:30
2019-02-15 15:39:39 +05:30
## Download a single artifact file by job ID
2018-03-17 18:26:18 +05:30
> Introduced in GitLab 10.0
2019-02-15 15:39:39 +05:30
Download a single artifact file from a job with a specified ID from within
2019-09-04 21:01:54 +05:30
the job's artifacts zipped archive. The file is extracted from the archive and
2019-02-15 15:39:39 +05:30
streamed to the client.
2018-03-17 18:26:18 +05:30
2020-04-08 14:13:33 +05:30
```plaintext
2018-03-17 18:26:18 +05:30
GET /projects/:id/jobs/:job_id/artifacts/*artifact_path
```
Parameters
2019-02-15 15:39:39 +05:30
| Attribute | Type | Required | Description |
|-----------------|----------------|----------|------------------------------------------------------------------------------------------------------------------|
2019-07-07 11:18:12 +05:30
| `id` | integer/string | yes | ID or [URL-encoded path of the project ](README.md#namespaced-path-encoding ) owned by the authenticated user. |
2019-09-30 21:07:59 +05:30
| `job_id` | integer | yes | The unique job identifier. |
2019-02-15 15:39:39 +05:30
| `artifact_path` | string | yes | Path to a file inside the artifacts archive. |
2018-03-17 18:26:18 +05:30
Example request:
2020-03-13 15:44:24 +05:30
```shell
2019-10-12 21:52:04 +05:30
curl --location --header "PRIVATE-TOKEN: < your_access_token > " "https://gitlab.example.com/api/v4/projects/1/jobs/5/artifacts/some/release/file.pdf"
2019-02-15 15:39:39 +05:30
```
Possible response status codes:
| Status | Description |
|-----------|--------------------------------------|
| 200 | Sends a single artifact file |
| 400 | Invalid path provided |
| 404 | Build not found or no file/artifacts |
## Download a single artifact file from specific tag or branch
2020-03-13 15:44:24 +05:30
> [Introduced](https://gitlab.com/gitlab-org/gitlab-foss/-/merge_requests/23538) in GitLab 11.5.
2019-02-15 15:39:39 +05:30
2019-09-30 21:07:59 +05:30
Download a single artifact file for a specific job of the latest successful
pipeline for the given reference name from within the job's artifacts archive.
The file is extracted from the archive and streamed to the client.
2019-02-15 15:39:39 +05:30
2020-04-08 14:13:33 +05:30
```plaintext
2019-02-15 15:39:39 +05:30
GET /projects/:id/jobs/artifacts/:ref_name/raw/*artifact_path?job=name
2018-03-17 18:26:18 +05:30
```
2019-02-15 15:39:39 +05:30
Parameters:
| Attribute | Type | Required | Description |
|-----------------|----------------|----------|------------------------------------------------------------------------------------------------------------------|
2019-07-07 11:18:12 +05:30
| `id` | integer/string | yes | ID or [URL-encoded path of the project ](README.md#namespaced-path-encoding ) owned by the authenticated user. |
2019-02-15 15:39:39 +05:30
| `ref_name` | string | yes | Branch or tag name in repository. HEAD or SHA references are not supported. |
| `artifact_path` | string | yes | Path to a file inside the artifacts archive. |
| `job` | string | yes | The name of the job. |
Example request:
2020-03-13 15:44:24 +05:30
```shell
2019-10-12 21:52:04 +05:30
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"
2019-02-15 15:39:39 +05:30
```
Possible response status codes:
2018-03-17 18:26:18 +05:30
| Status | Description |
|-----------|--------------------------------------|
| 200 | Sends a single artifact file |
| 400 | Invalid path provided |
| 404 | Build not found or no file/artifacts |
2019-12-21 20:55:43 +05:30
## Get a log file
2017-08-17 22:00:37 +05:30
2019-12-21 20:55:43 +05:30
Get a log (trace) of a specific job of a project:
2017-08-17 22:00:37 +05:30
2020-04-08 14:13:33 +05:30
```plaintext
2017-08-17 22:00:37 +05:30
GET /projects/:id/jobs/:job_id/trace
```
2019-02-15 15:39:39 +05:30
| Attribute | Type | Required | Description |
|-----------|----------------|----------|------------------------------------------------------------------------------------------------------------------|
2020-05-24 23:13:21 +05:30
| `id` | integer/string | yes | ID or [URL-encoded path of the project ](README.md#namespaced-path-encoding ) owned by the authenticated user. |
| `job_id` | integer | yes | ID of a job. |
2017-08-17 22:00:37 +05:30
2020-03-13 15:44:24 +05:30
```shell
2019-10-12 21:52:04 +05:30
curl --location --header "PRIVATE-TOKEN: < your_access_token > " "https://gitlab.example.com/api/v4/projects/1/jobs/8/trace"
2017-08-17 22:00:37 +05:30
```
2019-02-15 15:39:39 +05:30
Possible response status codes:
2017-08-17 22:00:37 +05:30
2019-12-21 20:55:43 +05:30
| Status | Description |
|-----------|-------------------------------|
| 200 | Serves the log file |
| 404 | Job not found or no log file |
2017-08-17 22:00:37 +05:30
## Cancel a job
Cancel a single job of a project
2020-04-08 14:13:33 +05:30
```plaintext
2017-08-17 22:00:37 +05:30
POST /projects/:id/jobs/:job_id/cancel
```
2019-02-15 15:39:39 +05:30
| Attribute | Type | Required | Description |
|-----------|----------------|----------|------------------------------------------------------------------------------------------------------------------|
2019-07-07 11:18:12 +05:30
| `id` | integer/string | yes | ID or [URL-encoded path of the project ](README.md#namespaced-path-encoding ) owned by the authenticated user. |
| `job_id` | integer | yes | ID of a job. |
2017-08-17 22:00:37 +05:30
2020-03-13 15:44:24 +05:30
```shell
2019-02-15 15:39:39 +05:30
curl --request POST --header "PRIVATE-TOKEN: < your_access_token > " "https://gitlab.example.com/api/v4/projects/1/jobs/1/cancel"
2017-08-17 22:00:37 +05:30
```
Example of response
```json
{
"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,
2019-09-04 21:01:54 +05:30
"allow_failure": false,
2017-08-17 22:00:37 +05:30
"created_at": "2016-01-11T10:13:33.506Z",
2018-12-05 23:21:45 +05:30
"started_at": "2016-01-11T10:14:09.526Z",
"finished_at": null,
"duration": 8,
2018-11-18 11:00:15 +05:30
"id": 42,
2017-08-17 22:00:37 +05:30
"name": "rubocop",
"ref": "master",
2018-11-20 20:47:30 +05:30
"artifacts": [],
2017-08-17 22:00:37 +05:30
"runner": null,
"stage": "test",
"status": "canceled",
"tag": false,
2018-11-18 11:00:15 +05:30
"web_url": "https://example.com/foo/bar/-/jobs/42",
2017-08-17 22:00:37 +05:30
"user": null
}
```
## Retry a job
Retry a single job of a project
2020-04-08 14:13:33 +05:30
```plaintext
2017-08-17 22:00:37 +05:30
POST /projects/:id/jobs/:job_id/retry
```
2019-02-15 15:39:39 +05:30
| Attribute | Type | Required | Description |
|-----------|----------------|----------|------------------------------------------------------------------------------------------------------------------|
2019-07-07 11:18:12 +05:30
| `id` | integer/string | yes | ID or [URL-encoded path of the project ](README.md#namespaced-path-encoding ) owned by the authenticated user. |
| `job_id` | integer | yes | ID of a job. |
2017-08-17 22:00:37 +05:30
2020-03-13 15:44:24 +05:30
```shell
2019-02-15 15:39:39 +05:30
curl --request POST --header "PRIVATE-TOKEN: < your_access_token > " "https://gitlab.example.com/api/v4/projects/1/jobs/1/retry"
2017-08-17 22:00:37 +05:30
```
Example of response
```json
{
"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,
2019-09-04 21:01:54 +05:30
"allow_failure": false,
2017-08-17 22:00:37 +05:30
"created_at": "2016-01-11T10:13:33.506Z",
2018-12-05 23:21:45 +05:30
"started_at": null,
2017-08-17 22:00:37 +05:30
"finished_at": null,
2018-12-05 23:21:45 +05:30
"duration": null,
2018-11-18 11:00:15 +05:30
"id": 42,
2017-08-17 22:00:37 +05:30
"name": "rubocop",
"ref": "master",
2018-11-20 20:47:30 +05:30
"artifacts": [],
2017-08-17 22:00:37 +05:30
"runner": null,
"stage": "test",
"status": "pending",
"tag": false,
2018-11-18 11:00:15 +05:30
"web_url": "https://example.com/foo/bar/-/jobs/42",
2017-08-17 22:00:37 +05:30
"user": null
}
```
## Erase a job
2019-12-21 20:55:43 +05:30
Erase a single job of a project (remove job artifacts and a job log)
2017-08-17 22:00:37 +05:30
2020-04-08 14:13:33 +05:30
```plaintext
2017-08-17 22:00:37 +05:30
POST /projects/:id/jobs/:job_id/erase
```
Parameters
2019-02-15 15:39:39 +05:30
| Attribute | Type | Required | Description |
|-----------|----------------|----------|------------------------------------------------------------------------------------------------------------------|
2019-07-07 11:18:12 +05:30
| `id` | integer/string | yes | ID or [URL-encoded path of the project ](README.md#namespaced-path-encoding ) owned by the authenticated user. |
| `job_id` | integer | yes | ID of a job. |
2017-08-17 22:00:37 +05:30
Example of request
2020-03-13 15:44:24 +05:30
```shell
2019-02-15 15:39:39 +05:30
curl --request POST --header "PRIVATE-TOKEN: < your_access_token > " "https://gitlab.example.com/api/v4/projects/1/jobs/1/erase"
2017-08-17 22:00:37 +05:30
```
Example of response
```json
{
"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,
2019-09-04 21:01:54 +05:30
"allow_failure": false,
2017-08-17 22:00:37 +05:30
"download_url": null,
2018-11-18 11:00:15 +05:30
"id": 42,
2017-08-17 22:00:37 +05:30
"name": "rubocop",
"ref": "master",
2018-11-20 20:47:30 +05:30
"artifacts": [],
2017-08-17 22:00:37 +05:30
"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",
2018-12-05 23:21:45 +05:30
"duration": 97.0,
2017-08-17 22:00:37 +05:30
"status": "failed",
"tag": false,
2018-11-18 11:00:15 +05:30
"web_url": "https://example.com/foo/bar/-/jobs/42",
2017-08-17 22:00:37 +05:30
"user": null
}
```
## Keep artifacts
Prevents artifacts from being deleted when expiration is set.
2020-04-08 14:13:33 +05:30
```plaintext
2017-08-17 22:00:37 +05:30
POST /projects/:id/jobs/:job_id/artifacts/keep
```
Parameters
2019-02-15 15:39:39 +05:30
| Attribute | Type | Required | Description |
|-----------|----------------|----------|------------------------------------------------------------------------------------------------------------------|
2019-07-07 11:18:12 +05:30
| `id` | integer/string | yes | ID or [URL-encoded path of the project ](README.md#namespaced-path-encoding ) owned by the authenticated user. |
| `job_id` | integer | yes | ID of a job. |
2017-08-17 22:00:37 +05:30
Example request:
2020-03-13 15:44:24 +05:30
```shell
2019-02-15 15:39:39 +05:30
curl --request POST --header "PRIVATE-TOKEN: < your_access_token > " "https://gitlab.example.com/api/v4/projects/1/jobs/1/artifacts/keep"
2017-08-17 22:00:37 +05:30
```
Example response:
```json
{
"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,
2019-09-04 21:01:54 +05:30
"allow_failure": false,
2017-08-17 22:00:37 +05:30
"download_url": null,
2018-11-18 11:00:15 +05:30
"id": 42,
2017-08-17 22:00:37 +05:30
"name": "rubocop",
"ref": "master",
2018-11-20 20:47:30 +05:30
"artifacts": [],
2017-08-17 22:00:37 +05:30
"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",
2018-12-05 23:21:45 +05:30
"duration": 97.0,
2017-08-17 22:00:37 +05:30
"status": "failed",
"tag": false,
2018-11-18 11:00:15 +05:30
"web_url": "https://example.com/foo/bar/-/jobs/42",
2017-08-17 22:00:37 +05:30
"user": null
}
```
2019-07-07 11:18:12 +05:30
## Delete artifacts
2020-03-13 15:44:24 +05:30
> [Introduced](https://gitlab.com/gitlab-org/gitlab-foss/-/merge_requests/25522) in GitLab 11.9.
2019-07-07 11:18:12 +05:30
Delete artifacts of a job.
2020-04-08 14:13:33 +05:30
```plaintext
2019-07-07 11:18:12 +05:30
DELETE /projects/:id/jobs/:job_id/artifacts
```
| Attribute | Type | Required | Description |
|-----------|----------------|----------|------------------------------------------------------------------------------------------------------------------|
| `id` | integer/string | yes | ID or [URL-encoded path of the project ](README.md#namespaced-path-encoding ) |
| `job_id` | integer | yes | ID of a job. |
Example request:
2020-03-13 15:44:24 +05:30
```shell
2019-07-07 11:18:12 +05:30
curl --request DELETE --header "PRIVATE-TOKEN: < your_access_token > " "https://gitlab.example.com/api/v4/projects/1/jobs/1/artifacts"
```
NOTE: **Note:**
At least Maintainer role is required to delete artifacts.
If the artifacts were deleted successfully, a response with status `204 No Content` is returned.
2017-08-17 22:00:37 +05:30
## Play a job
Triggers a manual action to start a job.
2020-04-08 14:13:33 +05:30
```plaintext
2017-08-17 22:00:37 +05:30
POST /projects/:id/jobs/:job_id/play
```
2019-02-15 15:39:39 +05:30
| Attribute | Type | Required | Description |
|-----------|----------------|----------|------------------------------------------------------------------------------------------------------------------|
2019-07-07 11:18:12 +05:30
| `id` | integer/string | yes | ID or [URL-encoded path of the project ](README.md#namespaced-path-encoding ) owned by the authenticated user. |
| `job_id` | integer | yes | ID of a job. |
2017-08-17 22:00:37 +05:30
2020-03-13 15:44:24 +05:30
```shell
2019-02-15 15:39:39 +05:30
curl --request POST --header "PRIVATE-TOKEN: < your_access_token > " "https://gitlab.example.com/api/v4/projects/1/jobs/1/play"
2017-08-17 22:00:37 +05:30
```
Example of response
```json
{
"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,
2019-09-04 21:01:54 +05:30
"allow_failure": false,
2017-08-17 22:00:37 +05:30
"created_at": "2016-01-11T10:13:33.506Z",
2018-12-05 23:21:45 +05:30
"started_at": null,
2017-08-17 22:00:37 +05:30
"finished_at": null,
2018-12-05 23:21:45 +05:30
"duration": null,
2018-11-18 11:00:15 +05:30
"id": 42,
2017-08-17 22:00:37 +05:30
"name": "rubocop",
"ref": "master",
2018-11-20 20:47:30 +05:30
"artifacts": [],
2017-08-17 22:00:37 +05:30
"runner": null,
"stage": "test",
"status": "started",
"tag": false,
2018-11-18 11:00:15 +05:30
"web_url": "https://example.com/foo/bar/-/jobs/42",
2017-08-17 22:00:37 +05:30
"user": null
}
```