- Disabling job artifacts
- Storing job artifacts
- Expiring artifacts
- Set the maximum file size of the artifacts
- Storage statistics
- Implementation details
Jobs artifacts administration
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:
-
Edit
/etc/gitlab/gitlab.rb
:gitlab_rails['artifacts_enabled'] = false
-
Save the file and reconfigure GitLab:
sudo gitlab-ctl reconfigure
-
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
-
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
-
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
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.
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
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
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.
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.
- Configure the object storage.
-
Migrate the artifacts:
Linux package (Omnibus)sudo gitlab-rake gitlab:artifacts:migrate
Dockersudo docker exec -t <container name> gitlab-rake gitlab:artifacts:migrate
Self-compiled (source)sudo -u git -H bundle exec rake gitlab:artifacts:migrate RAILS_ENV=production
- Optional. Track the progress and verify that all job artifacts migrated
successfully using the PostgreSQL console.
-
Open a PostgreSQL console:
Linux package (Omnibus)sudo gitlab-psql
Dockersudo docker exec -it <container_name> /bin/bash gitlab-psql
Self-compiled (source)sudo -u git -H psql -d gitlabhq_production
-
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:Linux package (Omnibus)sudo find /var/opt/gitlab/gitlab-rails/shared/artifacts -type f | grep -v tmp | wc -l
DockerAssuming you mounted
/var/opt/gitlab
to/srv/gitlab
:sudo find /srv/gitlab/gitlab-rails/shared/artifacts -type f | grep -v tmp | wc -l
Self-compiled (source)sudo find /home/git/gitlab/shared/artifacts -type f | grep -v tmp | wc -l
- If Geo is enabled, reverify all job artifacts.
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 artifacts back to local storage:
- Run
gitlab-rake gitlab:artifacts:migrate_to_local
. -
Selectively disable the artifacts’ storage in
gitlab.rb
. - Reconfigure GitLab.
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:
-
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
-
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
-
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
-
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
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 for groups and projects in:
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.