debian-mirror-gitlab/doc/ci/pipelines/job_artifacts.md

208 lines
7.7 KiB
Markdown
Raw Normal View History

2020-04-08 14:13:33 +05:30
---
2020-06-23 00:09:42 +05:30
stage: Verify
group: Continuous Integration
2021-02-22 17:27:13 +05:30
info: To determine the technical writer assigned to the Stage/Group associated with this page, see https://about.gitlab.com/handbook/engineering/ux/technical-writing/#assignments
2020-04-08 14:13:33 +05:30
disqus_identifier: 'https://docs.gitlab.com/ee/user/project/pipelines/job_artifacts.html'
type: reference, howto
---
2020-04-22 19:07:51 +05:30
# Job artifacts
2020-04-08 14:13:33 +05:30
2021-04-29 21:17:54 +05:30
> Introduced in [GitLab 12.4](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/16675), artifacts in internal and private projects can be previewed when [GitLab Pages access control](../../administration/pages/index.md#access-control) is enabled.
2020-04-08 14:13:33 +05:30
2021-04-29 21:17:54 +05:30
Jobs can output an archive of files and directories. This output is known as a job artifact.
2020-04-08 14:13:33 +05:30
2021-04-29 21:17:54 +05:30
You can download job artifacts by using the GitLab UI or the [API](../../api/job_artifacts.md#get-job-artifacts).
2020-04-08 14:13:33 +05:30
<i class="fa fa-youtube-play youtube" aria-hidden="true"></i>
2021-04-29 21:17:54 +05:30
For an overview of job artifacts, watch the video [GitLab CI pipelines, artifacts, and environments](https://www.youtube.com/watch?v=PCKDICEe10s).
Or, for an introduction, watch [GitLab CI pipeline tutorial for beginners](https://www.youtube.com/watch?v=Jav4vbUrqII).
2020-04-08 14:13:33 +05:30
2021-04-29 21:17:54 +05:30
For administrator information about job artifact storage, see [administering job artifacts](../../administration/job_artifacts.md).
2020-04-08 14:13:33 +05:30
2021-04-29 21:17:54 +05:30
## Create job artifacts
To create job artifacts, use the `artifacts` keyword in your `.gitlab-ci.yml` file:
2020-04-08 14:13:33 +05:30
```yaml
pdf:
script: xelatex mycv.tex
artifacts:
paths:
2020-07-28 23:09:34 +05:30
- mycv.pdf
2020-04-08 14:13:33 +05:30
expire_in: 1 week
```
2021-04-29 21:17:54 +05:30
In this example, a job named `pdf` calls the `xelatex` command to build a PDF file from the
LaTeX source file, `mycv.tex`.
2020-05-24 23:13:21 +05:30
2021-04-29 21:17:54 +05:30
The `paths` keyword determines which files to add to the job artifacts.
All paths to files and directories are relative to the repository where the job was created.
2020-05-24 23:13:21 +05:30
2021-04-29 21:17:54 +05:30
The `expire_in` keyword determines how long GitLab keeps the job artifacts.
You can also [use the UI to keep job artifacts from expiring](#download-job-artifacts).
If `expire_in` is not defined, the
[instance-wide setting](../../user/admin_area/settings/continuous_integration.md#default-artifacts-expiration)
is used.
2020-05-24 23:13:21 +05:30
2021-04-29 21:17:54 +05:30
If you run two types of pipelines (like branch and scheduled) for the same ref,
the pipeline that finishes later creates the job artifact.
2020-05-24 23:13:21 +05:30
2021-04-29 21:17:54 +05:30
For more examples, view the [keyword reference for the `.gitlab-ci.yml` file](../yaml/README.md#artifacts).
2020-05-24 23:13:21 +05:30
2021-04-29 21:17:54 +05:30
## Download job artifacts
2020-05-24 23:13:21 +05:30
2021-04-29 21:17:54 +05:30
You can download job artifacts or view the job archive:
2020-05-24 23:13:21 +05:30
2021-04-29 21:17:54 +05:30
- On the **Pipelines** page, to the right of the pipeline:
2020-05-24 23:13:21 +05:30
2021-04-29 21:17:54 +05:30
![Job artifacts in Pipelines page](img/job_artifacts_pipelines_page_v13_11.png)
2020-05-24 23:13:21 +05:30
2021-04-29 21:17:54 +05:30
- On the **Jobs** page, to the right of the job:
2020-05-24 23:13:21 +05:30
2021-04-29 21:17:54 +05:30
![Job artifacts in Jobs page](img/job_artifacts_jobs_page_v13_11.png)
2020-06-23 00:09:42 +05:30
2021-04-29 21:17:54 +05:30
- On a job's detail page. The **Keep** button indicates an `expire_in` value was set:
2020-06-23 00:09:42 +05:30
2021-04-29 21:17:54 +05:30
![Job artifacts browser button](img/job_artifacts_browser_button_v13_11.png)
2020-06-23 00:09:42 +05:30
2021-04-29 21:17:54 +05:30
- On a merge request, by the pipeline details:
2020-06-23 00:09:42 +05:30
2021-04-29 21:17:54 +05:30
![Job artifacts in merge request](img/job_artifacts_merge_request_v13_11.png)
2020-05-24 23:13:21 +05:30
2021-04-29 21:17:54 +05:30
- When browsing an archive:
2020-05-24 23:13:21 +05:30
2021-04-29 21:17:54 +05:30
![Job artifacts browser](img/job_artifacts_browser_v13_11.png)
2020-05-24 23:13:21 +05:30
2021-04-29 21:17:54 +05:30
If [GitLab Pages](../../administration/pages/index.md) is enabled in the project, you can preview
HTML files in the artifacts directly in your browser. If the project is internal or private, you must
enable [GitLab Pages access control](../../administration/pages/index.md#access-control) to preview
HTML files.
2020-05-24 23:13:21 +05:30
2021-04-29 21:17:54 +05:30
## View failed job artifacts
2020-05-24 23:13:21 +05:30
2021-04-29 21:17:54 +05:30
If the latest job has failed to upload the artifacts, you can see that
information in the UI.
2021-02-22 17:27:13 +05:30
2021-04-29 21:17:54 +05:30
![Latest artifacts button](img/job_latest_artifacts_browser.png)
2020-05-24 23:13:21 +05:30
2021-04-29 21:17:54 +05:30
## Delete job artifacts
2020-05-24 23:13:21 +05:30
2021-02-22 17:27:13 +05:30
WARNING:
2021-04-29 21:17:54 +05:30
This is a destructive action that leads to data loss. Use with caution.
2020-04-08 14:13:33 +05:30
2021-04-29 21:17:54 +05:30
You can delete a single job, which also removes the job's
artifacts and log. You must be:
2021-03-08 18:12:59 +05:30
2021-04-29 21:17:54 +05:30
- The owner of the job.
- A [maintainer](../../user/permissions.md#gitlab-cicd-permissions) of the project.
2021-03-08 18:12:59 +05:30
2021-04-29 21:17:54 +05:30
To delete a job:
2020-04-08 14:13:33 +05:30
2021-04-29 21:17:54 +05:30
1. Go to a job's detail page.
1. At the top right of the job's log, select the trash icon.
1. Confirm the deletion.
2020-04-08 14:13:33 +05:30
2021-04-29 21:17:54 +05:30
## Retrieve job artifacts for other projects
2020-04-08 14:13:33 +05:30
2021-04-29 21:17:54 +05:30
To retrieve a job artifact from a different project, you might need to use a
private token to [authenticate and download](../../api/job_artifacts.md#get-job-artifacts)
the artifact.
2020-04-08 14:13:33 +05:30
2021-04-29 21:17:54 +05:30
## How searching for job artifacts works
2020-04-08 14:13:33 +05:30
2021-01-03 14:25:43 +05:30
In [GitLab 13.5](https://gitlab.com/gitlab-org/gitlab/-/issues/201784) and later, artifacts
for [parent and child pipelines](../parent_child_pipelines.md) are searched in hierarchical
order from parent to child. For example, if both parent and child pipelines have a
2021-04-29 21:17:54 +05:30
job with the same name, the job artifact from the parent pipeline is returned.
2021-01-03 14:25:43 +05:30
2021-04-29 21:17:54 +05:30
## Access the latest job artifacts by URL
2020-04-08 14:13:33 +05:30
2021-06-08 01:23:25 +05:30
You can download job artifacts from the latest successful pipeline by using a URL.
2021-04-29 21:17:54 +05:30
To download the whole artifacts archive:
2020-04-08 14:13:33 +05:30
```plaintext
https://example.com/<namespace>/<project>/-/jobs/artifacts/<ref>/download?job=<job_name>
```
2021-04-29 21:17:54 +05:30
To download a single file from the artifacts:
2020-04-08 14:13:33 +05:30
```plaintext
https://example.com/<namespace>/<project>/-/jobs/artifacts/<ref>/raw/<path_to_file>?job=<job_name>
```
2021-04-29 21:17:54 +05:30
For example, to download the latest artifacts of the job named `coverage` in
the `main` branch of the `gitlab` project in the `gitlab-org`
namespace:
2020-04-08 14:13:33 +05:30
```plaintext
2021-04-29 21:17:54 +05:30
https://gitlab.com/gitlab-org/gitlab/-/jobs/artifacts/main/download?job=coverage
2020-04-08 14:13:33 +05:30
```
2021-04-29 21:17:54 +05:30
To download the file `coverage/index.html` from the same artifacts:
2020-04-08 14:13:33 +05:30
```plaintext
https://gitlab.com/gitlab-org/gitlab/-/jobs/artifacts/master/raw/coverage/index.html?job=coverage
```
2021-04-29 21:17:54 +05:30
To browse the latest job artifacts:
2020-04-08 14:13:33 +05:30
```plaintext
https://example.com/<namespace>/<project>/-/jobs/artifacts/<ref>/browse?job=<job_name>
```
For example:
```plaintext
https://gitlab.com/gitlab-org/gitlab/-/jobs/artifacts/master/browse?job=coverage
```
2021-04-29 21:17:54 +05:30
To download specific files, including HTML files that
2020-04-08 14:13:33 +05:30
are shown in [GitLab Pages](../../administration/pages/index.md):
```plaintext
https://example.com/<namespace>/<project>/-/jobs/artifacts/<ref>/file/<path>?job=<job_name>
```
2021-04-29 21:17:54 +05:30
For example, when a job `coverage` creates the artifact `htmlcov/index.html`:
2020-04-08 14:13:33 +05:30
```plaintext
https://gitlab.com/gitlab-org/gitlab/-/jobs/artifacts/master/file/htmlcov/index.html?job=coverage
```
2021-04-29 21:17:54 +05:30
## When job artifacts are deleted
2020-04-08 14:13:33 +05:30
2021-06-08 01:23:25 +05:30
See the [`expire_in`](../yaml/README.md#artifactsexpire_in) documentation for information on when
job artifacts are deleted.
2021-01-03 14:25:43 +05:30
2021-04-29 21:17:54 +05:30
### Keep artifacts from most recent successful jobs
2021-03-08 18:12:59 +05:30
> - [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/16267) in GitLab 13.0.
> - [Feature flag removed](https://gitlab.com/gitlab-org/gitlab/-/issues/229936) in GitLab 13.4.
> - [Made optional with a CI/CD setting](https://gitlab.com/gitlab-org/gitlab/-/issues/241026) in GitLab 13.8.
Keeping the latest artifacts can use a large amount of storage space in projects
with a lot of jobs or large artifacts. If the latest artifacts are not needed in
a project, you can disable this behavior to save space:
2021-04-29 21:17:54 +05:30
1. Go to the project's **Settings > CI/CD > Artifacts**.
1. Clear the **Keep artifacts from most recent successful jobs** checkbox.
2021-03-08 18:12:59 +05:30
2021-03-11 19:13:27 +05:30
You can disable this behavior for all projects on a self-managed instance in the
2021-04-29 21:17:54 +05:30
[instance's CI/CD settings](../../user/admin_area/settings/continuous_integration.md#keep-the-latest-artifacts-for-all-jobs-in-the-latest-successful-pipelines).
2021-03-11 19:13:27 +05:30
When you disable the feature, the latest artifacts do not immediately expire.
A new pipeline must run before the latest artifacts can expire and be deleted.
2021-04-29 21:17:54 +05:30
## Troubleshooting job artifacts
2021-01-03 14:25:43 +05:30
### Error message `No files to upload`
2021-04-29 21:17:54 +05:30
This message is often preceded by other errors or warnings that specify the filename and why it wasn't
generated. Check the job log for these messages.
2021-01-03 14:25:43 +05:30
2021-04-29 21:17:54 +05:30
If you find no helpful messages, retry the failed job after activating
2021-03-11 19:13:27 +05:30
[CI/CD debug logging](../variables/README.md#debug-logging).
2021-04-29 21:17:54 +05:30
This logging should provide information to help you investigate further.