Jobs artifacts administration

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:

  1. Edit /etc/gitlab/gitlab.rb:

    gitlab_rails['artifacts_enabled'] = false
    
  2. Save the file and reconfigure GitLab:

    sudo gitlab-ctl reconfigure
    

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.

The artifacts are stored by default in /var/opt/gitlab/gitlab-rails/shared/artifacts.

  1. 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"
    
  2. Save the file and reconfigure GitLab:

    sudo gitlab-ctl reconfigure
    

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.

caution
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.

  1. Configure the object storage.
  2. Migrate the artifacts:

    sudo gitlab-rake gitlab:artifacts:migrate
    
  3. Optional. Track the progress and verify that all job artifacts migrated successfully using the PostgreSQL console.
    1. Open a PostgreSQL console:

      sudo gitlab-psql
      
    2. Verify that all artifacts migrated to object storage with the following SQL query. The number of objectstg should be the same as total:

      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
      
  4. Verify that there are no files on disk in the artifacts directory:

    sudo find /var/opt/gitlab/gitlab-rails/shared/artifacts -type f | grep -v tmp | wc -l
    

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:

  1. Run gitlab-rake gitlab:artifacts:migrate_to_local.
  2. Selectively disable the artifacts’ storage in gitlab.rb.
  3. 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:

  1. 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 * * * *"
    
  2. Save the file and reconfigure GitLab:

    sudo gitlab-ctl reconfigure
    

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.