debian-mirror-gitlab/doc/api/jobs.md

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

929 lines
28 KiB
Markdown
Raw Permalink Normal View History

2020-10-24 23:57:45 +05:30
---
stage: Verify
2021-09-04 01:27:46 +05:30
group: Pipeline Execution
2022-11-25 23:54:43 +05:30
info: To determine the technical writer assigned to the Stage/Group associated with this page, see https://about.gitlab.com/handbook/product/ux/technical-writing/#assignments
2020-10-24 23:57:45 +05:30
---
2021-09-04 01:27:46 +05:30
# Jobs API **(FREE)**
2017-08-17 22:00:37 +05:30
## 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
2023-04-23 21:23:45 +05:30
By default, this request returns 20 results at a time because the API results [are paginated](rest/index.md#pagination)
This endpoint supports both offset-based and [keyset-based](rest/index.md#keyset-based-pagination) pagination. Keyset-based
pagination is recommended when requesting consecutive pages of results.
2022-04-04 11:22:00 +05:30
2020-04-08 14:13:33 +05:30
```plaintext
2017-08-17 22:00:37 +05:30
GET /projects/:id/jobs
```
2022-04-04 11:22:00 +05:30
| Attribute | Type | Required | Description |
|-----------|--------------------------------|------------------------|-------------|
2023-04-23 21:23:45 +05:30
| `id` | integer/string | **{check-circle}** Yes | ID or [URL-encoded path of the project](rest/index.md#namespaced-path-encoding) owned by the authenticated user. |
2022-08-27 11:52:29 +05:30
| `scope` | string **or** array of strings | **{dotted-circle}** No | Scope of jobs to show. Either one of or an array of the following: `created`, `pending`, `running`, `failed`, `success`, `canceled`, `skipped`, `waiting_for_resource`, 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
2020-06-23 00:09:42 +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",
2023-04-23 21:23:45 +05:30
"erased_at": null,
2020-01-01 13:55:28 +05:30
"duration": 0.173,
2021-06-08 01:23:25 +05:30
"queued_duration": 0.010,
2020-01-01 13:55:28 +05:30
"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",
2021-03-11 19:13:27 +05:30
"tag_list": [
"docker runner", "ubuntu18"
],
2020-01-01 13:55:28 +05:30
"id": 7,
"name": "teaspoon",
2017-08-17 22:00:37 +05:30
"pipeline": {
"id": 6,
2021-04-17 20:07:23 +05:30
"project_id": 1,
2021-09-04 01:27:46 +05:30
"ref": "main",
2017-08-17 22:00:37 +05:30
"sha": "0ff3ae198f8601a285adcf5c0fff204ee6fba5fd",
"status": "pending"
},
2021-09-04 01:27:46 +05:30
"ref": "main",
2017-08-17 22:00:37 +05:30
"runner": null,
"stage": "test",
"status": "failed",
2022-01-26 12:08:38 +05:30
"failure_reason": "script_failure",
2017-08-17 22:00:37 +05:30
"tag": false,
2020-01-01 13:55:28 +05:30
"web_url": "https://example.com/foo/bar/-/jobs/7",
2022-11-25 23:54:43 +05:30
"project": {
"ci_job_token_scope_enabled": false
},
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",
2023-04-23 21:23:45 +05:30
"erased_at": null,
2020-01-01 13:55:28 +05:30
"duration": 0.192,
2021-06-08 01:23:25 +05:30
"queued_duration": 0.023,
2020-01-01 13:55:28 +05:30
"artifacts_expire_at": "2016-01-23T17:54:24.921Z",
2021-03-11 19:13:27 +05:30
"tag_list": [
"docker runner", "win10-2004"
],
2020-01-01 13:55:28 +05:30
"id": 6,
"name": "rspec:other",
2017-08-17 22:00:37 +05:30
"pipeline": {
"id": 6,
2021-04-17 20:07:23 +05:30
"project_id": 1,
2021-09-04 01:27:46 +05:30
"ref": "main",
2017-08-17 22:00:37 +05:30
"sha": "0ff3ae198f8601a285adcf5c0fff204ee6fba5fd",
"status": "pending"
},
2021-09-04 01:27:46 +05:30
"ref": "main",
2018-11-20 20:47:30 +05:30
"artifacts": [],
2017-08-17 22:00:37 +05:30
"runner": null,
"stage": "test",
"status": "failed",
2022-01-26 12:08:38 +05:30
"failure_reason": "stuck_or_timeout_failure",
2017-08-17 22:00:37 +05:30
"tag": false,
2020-01-01 13:55:28 +05:30
"web_url": "https://example.com/foo/bar/-/jobs/6",
2022-11-25 23:54:43 +05:30
"project": {
"ci_job_token_scope_enabled": false
},
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.
2023-04-23 21:23:45 +05:30
By default, this request returns 20 results at a time because the API results [are paginated](rest/index.md#pagination)
2022-04-04 11:22:00 +05:30
2020-04-08 14:13:33 +05:30
```plaintext
2017-08-17 22:00:37 +05:30
GET /projects/:id/pipelines/:pipeline_id/jobs
```
2022-04-04 11:22:00 +05:30
| Attribute | Type | Required | Description |
|-------------------|--------------------------------|------------------------|-------------|
2023-04-23 21:23:45 +05:30
| `id` | integer/string | **{check-circle}** Yes | ID or [URL-encoded path of the project](rest/index.md#namespaced-path-encoding) owned by the authenticated user. |
2022-04-04 11:22:00 +05:30
| `pipeline_id` | integer | **{check-circle}** Yes | ID of a pipeline. Can also be obtained in CI jobs via the [predefined CI variable](../ci/variables/predefined_variables.md) `CI_PIPELINE_ID`. |
2022-08-27 11:52:29 +05:30
| `scope` | string **or** array of strings | **{dotted-circle}** No | Scope of jobs to show. Either one of or an array of the following: `created`, `pending`, `running`, `failed`, `success`, `canceled`, `skipped`, `waiting_for_resource`, or `manual`. All jobs are returned if `scope` is not provided. |
2022-04-04 11:22:00 +05:30
| `include_retried` | boolean | **{dotted-circle}** No | Include retried jobs in the response. Defaults to `false`. [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/272627) in GitLab 13.9. |
2017-08-17 22:00:37 +05:30
2020-03-13 15:44:24 +05:30
```shell
2020-06-23 00:09:42 +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",
2023-04-23 21:23:45 +05:30
"erased_at": null,
2018-12-05 23:21:45 +05:30
"duration": 0.192,
2021-06-08 01:23:25 +05:30
"queued_duration": 0.023,
2018-11-18 11:00:15 +05:30
"artifacts_expire_at": "2016-01-23T17:54:24.921Z",
2021-03-11 19:13:27 +05:30
"tag_list": [
"docker runner", "ubuntu18"
],
2018-11-08 19:23:39 +05:30
"id": 6,
"name": "rspec:other",
2017-08-17 22:00:37 +05:30
"pipeline": {
"id": 6,
2021-04-17 20:07:23 +05:30
"project_id": 1,
2021-09-04 01:27:46 +05:30
"ref": "main",
2017-08-17 22:00:37 +05:30
"sha": "0ff3ae198f8601a285adcf5c0fff204ee6fba5fd",
"status": "pending"
},
2021-09-04 01:27:46 +05:30
"ref": "main",
2018-11-20 20:47:30 +05:30
"artifacts": [],
2017-08-17 22:00:37 +05:30
"runner": null,
"stage": "test",
"status": "failed",
2022-01-26 12:08:38 +05:30
"failure_reason": "stuck_or_timeout_failure",
2017-08-17 22:00:37 +05:30
"tag": false,
2018-11-18 11:00:15 +05:30
"web_url": "https://example.com/foo/bar/-/jobs/6",
2022-11-25 23:54:43 +05:30
"project": {
"ci_job_token_scope_enabled": false
},
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",
2023-04-23 21:23:45 +05:30
"erased_at": null,
2018-12-05 23:21:45 +05:30
"duration": 0.173,
2021-06-08 01:23:25 +05:30
"queued_duration": 0.023,
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",
2021-03-11 19:13:27 +05:30
"tag_list": [
"docker runner", "ubuntu18"
],
2018-11-08 19:23:39 +05:30
"id": 7,
"name": "teaspoon",
2017-08-17 22:00:37 +05:30
"pipeline": {
"id": 6,
2021-04-17 20:07:23 +05:30
"project_id": 1,
2021-09-04 01:27:46 +05:30
"ref": "main",
2017-08-17 22:00:37 +05:30
"sha": "0ff3ae198f8601a285adcf5c0fff204ee6fba5fd",
"status": "pending"
},
2021-09-04 01:27:46 +05:30
"ref": "main",
2017-08-17 22:00:37 +05:30
"runner": null,
"stage": "test",
"status": "failed",
2022-01-26 12:08:38 +05:30
"failure_reason": "script_failure",
2017-08-17 22:00:37 +05:30
"tag": false,
2018-11-18 11:00:15 +05:30
"web_url": "https://example.com/foo/bar/-/jobs/7",
2022-11-25 23:54:43 +05:30
"project": {
"ci_job_token_scope_enabled": false
},
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
}
}
]
```
2021-12-11 22:18:48 +05:30
In GitLab 13.3 and later, this endpoint [returns data for any pipeline](pipelines.md#get-a-single-pipeline)
2022-10-11 01:57:18 +05:30
including [child pipelines](../ci/pipelines/downstream_pipelines.md#parent-child-pipelines).
2020-10-24 23:57:45 +05:30
2021-03-11 19:13:27 +05:30
In GitLab 13.5 and later, this endpoint does not return retried jobs in the response
2021-04-29 21:17:54 +05:30
by default. Additionally, jobs are sorted by ID in descending order (newest first).
In earlier GitLab versions, jobs are sorted by ID in ascending order (oldest first).
2021-03-11 19:13:27 +05:30
In GitLab 13.9 and later, this endpoint can include retried jobs in the response
with `include_retried` set to `true`.
2023-06-20 00:43:36 +05:30
## List pipeline trigger jobs
2020-06-23 00:09:42 +05:30
2023-06-20 00:43:36 +05:30
Get a list of trigger jobs for a pipeline.
2020-06-23 00:09:42 +05:30
```plaintext
GET /projects/:id/pipelines/:pipeline_id/bridges
```
2022-04-04 11:22:00 +05:30
| Attribute | Type | Required | Description |
|---------------|--------------------------------|------------------------|-------------|
2023-04-23 21:23:45 +05:30
| `id` | integer/string | **{check-circle}** Yes | ID or [URL-encoded path of the project](rest/index.md#namespaced-path-encoding) owned by the authenticated user. |
2022-04-04 11:22:00 +05:30
| `pipeline_id` | integer | **{check-circle}** Yes | ID of a pipeline. |
2022-08-27 11:52:29 +05:30
| `scope` | string **or** array of strings | **{dotted-circle}** No | Scope of jobs to show. Either one of or an array of the following: `created`, `pending`, `running`, `failed`, `success`, `canceled`, `skipped`, `waiting_for_resource`, or `manual`. All jobs are returned if `scope` is not provided. |
2020-06-23 00:09:42 +05:30
```shell
2021-02-22 17:27:13 +05:30
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/1/pipelines/6/bridges?scope[]=pending&scope[]=running"
2020-06-23 00:09:42 +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,
"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",
2023-04-23 21:23:45 +05:30
"erased_at": null,
2020-06-23 00:09:42 +05:30
"duration": 240,
2021-06-08 01:23:25 +05:30
"queued_duration": 0.123,
2020-06-23 00:09:42 +05:30
"id": 7,
"name": "teaspoon",
"pipeline": {
"id": 6,
2021-04-17 20:07:23 +05:30
"project_id": 1,
2021-09-04 01:27:46 +05:30
"ref": "main",
2020-06-23 00:09:42 +05:30
"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"
},
2021-09-04 01:27:46 +05:30
"ref": "main",
2020-06-23 00:09:42 +05:30
"stage": "test",
"status": "pending",
"tag": false,
"web_url": "https://example.com/foo/bar/-/jobs/7",
2022-10-11 01:57:18 +05:30
"project": {
"ci_job_token_scope_enabled": false
},
2020-06-23 00:09:42 +05:30
"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",
2021-09-04 01:27:46 +05:30
"ref": "main",
2020-06-23 00:09:42 +05:30
"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"
}
}
]
```
2021-04-17 20:07:23 +05:30
## Get job token's job
2021-04-29 21:17:54 +05:30
> [Introduced](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/51727) in GitLab 13.10.
2021-04-17 20:07:23 +05:30
Retrieve the job that generated a job token.
```plaintext
GET /job
```
2021-12-11 22:18:48 +05:30
Examples (must run as part of the [`script`](../ci/yaml/index.md#script) section of a [CI/CD job](../ci/jobs/index.md)):
2021-04-17 20:07:23 +05:30
```shell
2021-12-11 22:18:48 +05:30
curl --header "Authorization: Bearer $CI_JOB_TOKEN" "${CI_API_V4_URL}/job"
curl --header "JOB-TOKEN: $CI_JOB_TOKEN" "${CI_API_V4_URL}/job"
curl "${CI_API_V4_URL}/job?job_token=$CI_JOB_TOKEN"
2021-04-17 20:07:23 +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,
"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",
2023-04-23 21:23:45 +05:30
"erased_at": null,
2021-04-17 20:07:23 +05:30
"duration": 0.465,
2021-06-08 01:23:25 +05:30
"queued_duration": 0.123,
2021-04-17 20:07:23 +05:30
"artifacts_expire_at": "2016-01-23T17:54:31.198Z",
"id": 8,
"name": "rubocop",
"pipeline": {
"id": 6,
"project_id": 1,
2021-09-04 01:27:46 +05:30
"ref": "main",
2021-04-17 20:07:23 +05:30
"sha": "0ff3ae198f8601a285adcf5c0fff204ee6fba5fd",
"status": "pending"
},
2021-09-04 01:27:46 +05:30
"ref": "main",
2021-04-17 20:07:23 +05:30
"artifacts": [],
"runner": null,
"stage": "test",
"status": "failed",
2022-01-26 12:08:38 +05:30
"failure_reason": "script_failure",
2021-04-17 20:07:23 +05:30
"tag": false,
"web_url": "https://example.com/foo/bar/-/jobs/8",
2022-10-11 01:57:18 +05:30
"project": {
"ci_job_token_scope_enabled": false
},
2021-04-17 20:07:23 +05:30
"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": ""
}
}
```
2022-05-07 20:08:51 +05:30
## Get GitLab agent by `CI_JOB_TOKEN` **(PREMIUM)**
2021-04-29 21:17:54 +05:30
2021-11-11 11:23:49 +05:30
> [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/324269) in GitLab 13.11.
2021-04-29 21:17:54 +05:30
2022-01-26 12:08:38 +05:30
Retrieve the job that generated the `CI_JOB_TOKEN`, along with a list of allowed
[agents](../user/clusters/agent/index.md).
2021-04-29 21:17:54 +05:30
```plaintext
GET /job/allowed_agents
```
Supported attributes:
2022-04-04 11:22:00 +05:30
| Attribute | Type | Required | Description |
|----------------|----------|------------------------|-------------|
| `CI_JOB_TOKEN` | string | **{check-circle}** Yes | Token value associated with the GitLab-provided `CI_JOB_TOKEN` variable. |
2021-04-29 21:17:54 +05:30
Example request:
```shell
curl --header "JOB-TOKEN: <CI_JOB_TOKEN>" "https://gitlab.example.com/api/v4/job/allowed_agents"
curl "https://gitlab.example.com/api/v4/job/allowed_agents?job_token=<CI_JOB_TOKEN>"
```
Example response:
```json
{
2023-03-04 22:38:38 +05:30
"allowed_agents": [
{
"id": 1,
"config_project": {
2021-04-29 21:17:54 +05:30
"id": 1,
2023-03-04 22:38:38 +05:30
"description": null,
"name": "project1",
"name_with_namespace": "John Doe2 / project1",
"path": "project1",
"path_with_namespace": "namespace1/project1",
"created_at": "2022-11-16T14:51:50.579Z"
2021-04-29 21:17:54 +05:30
}
2023-03-04 22:38:38 +05:30
}
],
2021-04-29 21:17:54 +05:30
"job": {
2023-03-04 22:38:38 +05:30
"id": 1
2021-04-29 21:17:54 +05:30
},
"pipeline": {
2023-03-04 22:38:38 +05:30
"id": 2
2021-04-29 21:17:54 +05:30
},
"project": {
"id": 1,
2023-03-04 22:38:38 +05:30
"groups": [
{
"id": 1
},
{
"id": 2
},
{
"id": 3
}
]
2021-04-29 21:17:54 +05:30
},
"user": {
"id": 2,
"name": "John Doe3",
"username": "user2",
"state": "active",
"avatar_url": "https://www.gravatar.com/avatar/10fc7f102b",
"web_url": "http://localhost/user2"
}
}
```
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
```
2022-04-04 11:22:00 +05:30
| Attribute | Type | Required | Description |
|-----------|----------------|------------------------|-------------|
2023-04-23 21:23:45 +05:30
| `id` | integer/string | **{check-circle}** Yes | ID or [URL-encoded path of the project](rest/index.md#namespaced-path-encoding) owned by the authenticated user. |
2022-04-04 11:22:00 +05:30
| `job_id` | integer | **{check-circle}** 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",
2023-04-23 21:23:45 +05:30
"erased_at": null,
2018-12-05 23:21:45 +05:30
"duration": 0.465,
2021-06-08 01:23:25 +05:30
"queued_duration": 0.010,
2018-11-08 19:23:39 +05:30
"artifacts_expire_at": "2016-01-23T17:54:31.198Z",
2021-03-11 19:13:27 +05:30
"tag_list": [
"docker runner", "macos-10.15"
],
2017-08-17 22:00:37 +05:30
"id": 8,
"name": "rubocop",
"pipeline": {
"id": 6,
2021-04-17 20:07:23 +05:30
"project_id": 1,
2021-09-04 01:27:46 +05:30
"ref": "main",
2017-08-17 22:00:37 +05:30
"sha": "0ff3ae198f8601a285adcf5c0fff204ee6fba5fd",
"status": "pending"
},
2021-09-04 01:27:46 +05:30
"ref": "main",
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",
2022-10-11 01:57:18 +05:30
"project": {
"ci_job_token_scope_enabled": false
},
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
}
}
```
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
```
2022-04-04 11:22:00 +05:30
| Attribute | Type | Required | Description |
|-----------|----------------|------------------------|-------------|
2023-04-23 21:23:45 +05:30
| `id` | integer/string | **{check-circle}** Yes | ID or [URL-encoded path of the project](rest/index.md#namespaced-path-encoding) owned by the authenticated user. |
2022-04-04 11:22:00 +05:30
| `job_id` | integer | **{check-circle}** 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
```
2022-04-04 11:22:00 +05:30
| Attribute | Type | Required | Description |
|-----------|----------------|------------------------|-------------|
2023-04-23 21:23:45 +05:30
| `id` | integer/string | **{check-circle}** Yes | ID or [URL-encoded path of the project](rest/index.md#namespaced-path-encoding) owned by the authenticated user. |
2022-04-04 11:22:00 +05:30
| `job_id` | integer | **{check-circle}** 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,
2023-04-23 21:23:45 +05:30
"erased_at": null,
2018-12-05 23:21:45 +05:30
"duration": 8,
2021-06-08 01:23:25 +05:30
"queued_duration": 0.010,
2022-08-13 15:12:31 +05:30
"id": 1,
2017-08-17 22:00:37 +05:30
"name": "rubocop",
2021-09-04 01:27:46 +05:30
"ref": "main",
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,
2022-08-27 11:52:29 +05:30
"web_url": "https://example.com/foo/bar/-/jobs/1",
2022-10-11 01:57:18 +05:30
"project": {
"ci_job_token_scope_enabled": false
},
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
```
2022-04-04 11:22:00 +05:30
| Attribute | Type | Required | Description |
|-----------|----------------|------------------------|-------------|
2023-04-23 21:23:45 +05:30
| `id` | integer/string | **{check-circle}** Yes | ID or [URL-encoded path of the project](rest/index.md#namespaced-path-encoding) owned by the authenticated user. |
2022-04-04 11:22:00 +05:30
| `job_id` | integer | **{check-circle}** 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,
2023-04-23 21:23:45 +05:30
"erased_at": null,
2018-12-05 23:21:45 +05:30
"duration": null,
2021-06-08 01:23:25 +05:30
"queued_duration": 0.010,
2022-08-13 15:12:31 +05:30
"id": 1,
2017-08-17 22:00:37 +05:30
"name": "rubocop",
2021-09-04 01:27:46 +05:30
"ref": "main",
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,
2022-08-27 11:52:29 +05:30
"web_url": "https://example.com/foo/bar/-/jobs/1",
2022-10-11 01:57:18 +05:30
"project": {
"ci_job_token_scope_enabled": false
},
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
2022-04-04 11:22:00 +05:30
| Attribute | Type | Required | Description |
|-----------|----------------|------------------------|-------------|
2023-04-23 21:23:45 +05:30
| `id` | integer/string | **{check-circle}** Yes | ID or [URL-encoded path of the project](rest/index.md#namespaced-path-encoding) owned by the authenticated user. |
2022-04-04 11:22:00 +05:30
| `job_id` | integer | **{check-circle}** 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,
2022-08-13 15:12:31 +05:30
"id": 1,
2017-08-17 22:00:37 +05:30
"name": "rubocop",
2021-09-04 01:27:46 +05:30
"ref": "main",
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",
2023-04-23 21:23:45 +05:30
"erased_at": "2016-01-11T11:30:19.914Z",
2018-12-05 23:21:45 +05:30
"duration": 97.0,
2021-06-08 01:23:25 +05:30
"queued_duration": 0.010,
2017-08-17 22:00:37 +05:30
"status": "failed",
"tag": false,
2022-08-27 11:52:29 +05:30
"web_url": "https://example.com/foo/bar/-/jobs/1",
2022-10-11 01:57:18 +05:30
"project": {
"ci_job_token_scope_enabled": false
},
2017-08-17 22:00:37 +05:30
"user": null
}
```
2022-01-26 12:08:38 +05:30
NOTE:
You can't delete archived jobs with the API, but you can
[delete job artifacts and logs from jobs completed before a specific date](../administration/job_artifacts.md#delete-job-artifacts-and-logs-from-jobs-completed-before-a-specific-date)
2022-05-07 20:08:51 +05:30
## Run a job
2017-08-17 22:00:37 +05:30
2022-10-11 01:57:18 +05:30
For a job in manual status, trigger an action to start the job.
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/play
```
2022-05-07 20:08:51 +05:30
| Attribute | Type | Required | Description |
|----------------------------|-----------------|------------------------|-------------|
2023-04-23 21:23:45 +05:30
| `id` | integer/string | **{check-circle}** Yes | ID or [URL-encoded path of the project](rest/index.md#namespaced-path-encoding) owned by the authenticated user. |
2022-05-07 20:08:51 +05:30
| `job_id` | integer | **{check-circle}** Yes | ID of a job. |
| `job_variables_attributes` | array of hashes | **{dotted-circle}** No | An array containing the custom variables available to the job. [Introduced in](https://gitlab.com/gitlab-org/gitlab/-/issues/37267) GitLab 14.9. |
Example request:
2017-08-17 22:00:37 +05:30
2020-03-13 15:44:24 +05:30
```shell
2023-07-09 08:55:56 +05:30
curl --request POST "https://gitlab.example.com/api/v4/projects/1/jobs/1/play" \
--header "Content-Type: application/json" \
--header "PRIVATE-TOKEN: <your_access_token>" \
2022-05-07 20:08:51 +05:30
--data @variables.json
2017-08-17 22:00:37 +05:30
```
2022-05-07 20:08:51 +05:30
`@variables.json` is structured like:
```json
{
"job_variables_attributes": [
{
"key": "TEST_VAR_1",
"value": "test1"
},
{
"key": "TEST_VAR_2",
"value": "test2"
}
]
}
```
Example response:
2017-08-17 22:00:37 +05:30
```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,
2023-04-23 21:23:45 +05:30
"erased_at": null,
2018-12-05 23:21:45 +05:30
"duration": null,
2021-06-08 01:23:25 +05:30
"queued_duration": 0.010,
2022-08-13 15:12:31 +05:30
"id": 1,
2017-08-17 22:00:37 +05:30
"name": "rubocop",
2021-09-04 01:27:46 +05:30
"ref": "main",
2018-11-20 20:47:30 +05:30
"artifacts": [],
2017-08-17 22:00:37 +05:30
"runner": null,
"stage": "test",
2021-06-08 01:23:25 +05:30
"status": "pending",
2017-08-17 22:00:37 +05:30
"tag": false,
2022-08-27 11:52:29 +05:30
"web_url": "https://example.com/foo/bar/-/jobs/1",
2022-10-11 01:57:18 +05:30
"project": {
"ci_job_token_scope_enabled": false
},
2017-08-17 22:00:37 +05:30
"user": null
}
```