Jobs artifacts administration
DETAILS: Tier: Free, Premium, Ultimate Offering: Self-managed
This is the administration documentation. To learn how to use job artifacts in your GitLab CI/CD pipeline, see the job artifacts configuration documentation.
An artifact is a list of files and directories attached to a job after it finishes. This feature is enabled by default in all GitLab installations.
Disabling job artifacts
To disable artifacts site-wide:
::Tabs
:::TabTitle Linux package (Omnibus)
-
Edit
/etc/gitlab/gitlab.rb
:gitlab_rails['artifacts_enabled'] = false
-
Save the file and reconfigure GitLab:
sudo gitlab-ctl reconfigure
:::TabTitle Helm chart (Kubernetes)
-
Export the Helm values:
helm get values gitlab > gitlab_values.yaml
-
Edit
gitlab_values.yaml
:global: appConfig: artifacts: enabled: false
-
Save the file and apply the new values:
helm upgrade -f gitlab_values.yaml gitlab gitlab/gitlab
:::TabTitle Docker
-
Edit
docker-compose.yml
:version: "3.6" services: gitlab: environment: GITLAB_OMNIBUS_CONFIG: | gitlab_rails['artifacts_enabled'] = false
-
Save the file and restart GitLab:
docker compose up -d
:::TabTitle Self-compiled (source)
-
Edit
/home/git/gitlab/config/gitlab.yml
:production: &base artifacts: enabled: false
-
Save the file and restart GitLab:
# For systems running systemd sudo systemctl restart gitlab.target # For systems running SysV init sudo service gitlab restart
::EndTabs
Storing job artifacts
GitLab Runner can upload an archive containing the job artifacts to GitLab. By default,
this is done when the job succeeds, but can also be done on failure, or always, with the
artifacts:when
parameter.
Most artifacts are compressed by GitLab Runner before being sent to the coordinator. The exception to this is reports artifacts, which are compressed after uploading.
Using local storage
If you're using the Linux package or have a self-compiled installation, you can change the location where the artifacts are stored locally.
NOTE: For Docker installations, you can change the path where your data is mounted. For the Helm chart, use object storage.
::Tabs
:::TabTitle Linux package (Omnibus)
The artifacts are stored by default in /var/opt/gitlab/gitlab-rails/shared/artifacts
.
-
To change the storage path, for example to
/mnt/storage/artifacts
, edit/etc/gitlab/gitlab.rb
and add the following line:gitlab_rails['artifacts_path'] = "/mnt/storage/artifacts"
-
Save the file and reconfigure GitLab:
sudo gitlab-ctl reconfigure
:::TabTitle Self-compiled (source)
The artifacts are stored by default in /home/git/gitlab/shared/artifacts
.
-
To change the storage path, for example to
/mnt/storage/artifacts
, edit/home/git/gitlab/config/gitlab.yml
and add or amend the following lines:production: &base artifacts: enabled: true path: /mnt/storage/artifacts
-
Save the file and restart GitLab:
# For systems running systemd sudo systemctl restart gitlab.target # For systems running SysV init sudo service gitlab restart
::EndTabs
Using object storage
If you don't want to use the local disk where GitLab is installed to store the artifacts, you can use an object storage like AWS S3 instead.
If you configure GitLab to store artifacts on object storage, you may also want to eliminate local disk usage for job logs. In both cases, job logs are archived and moved to object storage when the job completes.
WARNING: In a multi-server setup you must use one of the options to eliminate local disk usage for job logs, or job logs could be lost.
In GitLab 13.2 and later, you should use the consolidated object storage settings.
Migrating to object storage
You can migrate the job artifacts from local storage to object storage. The processing is done in a background worker and requires no downtime.
-
Migrate the artifacts:
::Tabs
:::TabTitle Linux package (Omnibus)
sudo gitlab-rake gitlab:artifacts:migrate
:::TabTitle Docker
sudo docker exec -t <container name> gitlab-rake gitlab:artifacts:migrate
:::TabTitle Self-compiled (source)
sudo -u git -H bundle exec rake gitlab:artifacts:migrate RAILS_ENV=production
::EndTabs
-
Optional. Track the progress and verify that all job artifacts migrated successfully using the PostgreSQL console.
-
Open a PostgreSQL console:
::Tabs
:::TabTitle Linux package (Omnibus)
sudo gitlab-psql
:::TabTitle Docker
sudo docker exec -it <container_name> /bin/bash gitlab-psql
:::TabTitle Self-compiled (source)
sudo -u git -H psql -d gitlabhq_production
::EndTabs
-
Verify that all artifacts migrated to object storage with the following SQL query. The number of
objectstg
should be the same astotal
:gitlabhq_production=# SELECT count(*) AS total, sum(case when file_store = '1' then 1 else 0 end) AS filesystem, sum(case when file_store = '2' then 1 else 0 end) AS objectstg FROM ci_job_artifacts; total | filesystem | objectstg ------+------------+----------- 19 | 0 | 19
-
-
Verify that there are no files on disk in the
artifacts
directory:::Tabs
:::TabTitle Linux package (Omnibus)
sudo find /var/opt/gitlab/gitlab-rails/shared/artifacts -type f | grep -v tmp | wc -l
:::TabTitle Docker
Assuming you mounted
/var/opt/gitlab
to/srv/gitlab
:sudo find /srv/gitlab/gitlab-rails/shared/artifacts -type f | grep -v tmp | wc -l
:::TabTitle Self-compiled (source)
sudo find /home/git/gitlab/shared/artifacts -type f | grep -v tmp | wc -l
::EndTabs
In some cases, you need to run the orphan artifact file cleanup Rake task to clean up orphaned artifacts.
Migrating from object storage to local storage
To migrate back to local storage, you must selectively disable the artifacts storage.
Expiring artifacts
If artifacts:expire_in
is used to set
an expiry for the artifacts, they are marked for deletion right after that date passes.
Otherwise, they expire per the default artifacts expiration setting.
Artifacts are deleted by the expire_build_artifacts_worker
cron job which Sidekiq
runs every 7 minutes (*/7 * * * *
in Cron syntax).
To change the default schedule on which expired artifacts are deleted:
::Tabs
:::TabTitle Linux package (Omnibus)
-
Edit
/etc/gitlab/gitlab.rb
and add the following line (or uncomment it if it already exists and is commented out), substituting your schedule in cron syntax:gitlab_rails['expire_build_artifacts_worker_cron'] = "*/7 * * * *"
-
Save the file and reconfigure GitLab:
sudo gitlab-ctl reconfigure
:::TabTitle Helm chart (Kubernetes)
-
Export the Helm values:
helm get values gitlab > gitlab_values.yaml
-
Edit
gitlab_values.yaml
:global: appConfig: cron_jobs: expire_build_artifacts_worker: cron: "*/7 * * * *"
-
Save the file and apply the new values:
helm upgrade -f gitlab_values.yaml gitlab gitlab/gitlab
:::TabTitle Docker
-
Edit
docker-compose.yml
:version: "3.6" services: gitlab: environment: GITLAB_OMNIBUS_CONFIG: | gitlab_rails['expire_build_artifacts_worker_cron'] = "*/7 * * * *"
-
Save the file and restart GitLab:
docker compose up -d
:::TabTitle Self-compiled (source)
-
Edit
/home/git/gitlab/config/gitlab.yml
:production: &base cron_jobs: expire_build_artifacts_worker: cron: "*/7 * * * *"
-
Save the file and restart GitLab:
# For systems running systemd sudo systemctl restart gitlab.target # For systems running SysV init sudo service gitlab restart
::EndTabs
Set the maximum file size of the artifacts
If artifacts are enabled, you can change the maximum file size of the artifacts through the Admin Area settings.
Storage statistics
You can see the total storage used for job artifacts on groups and projects in the administration area, as well as through the groups and projects APIs.
Implementation details
When GitLab receives an artifacts archive, an archive metadata file is also generated by GitLab Workhorse. This metadata file describes all the entries that are located in the artifacts archive itself. The metadata file is in a binary format, with additional Gzip compression.
GitLab doesn't extract the artifacts archive to save space, memory, and disk I/O. It instead inspects the metadata file which contains all the relevant information. This is especially important when there is a lot of artifacts, or an archive is a very large file.
When selecting a specific file, GitLab Workhorse extracts it from the archive and the download begins. This implementation saves space, memory and disk I/O.