Say Goodbye to Artifacts in GitLab Once and for All?

Hey guys, I have a self-hosted GitLab and I am wondering if it is possible to delete only the artifacts (beside gui)?
I know that they are deleted when pipelines or jobs are removed, but is it possible to delete just the artifacts?
If it is possible, then how to delete all artifacts older than one hour, month, year?
Is it possible to set it in gitlab.rb, so it will be run automatically and continuously by itself?

The docs seem to show that you can: Job artifacts | GitLab

if you have admin privileges on your Gitlab server also go to Admin → Settings → CI/CD → Default artifacts expiration and set it to 30 days or however long you want to keep them for.

Thanks for response, but I would prefer some code/api resolution for this, as I have accumulated bunch of artifacts for some time and I have thousand of them in many different projects. I ran curl --request DELETE --header "PRIVATE-TOKEN: token" "https:url/api/v4/projects/project_id/artifacts and it gave me response "message":"202 Accepted".
After that i ran housekeeping, but I still can see those artifacts.
I have also set Default artifacts expiration to 1 min and

gitlab_rails['expire_build_artifacts_worker_cron'] = "*/1 * * * *"
gitlab_rails['artifacts_enabled'] = false

I found solution:

  • go to project as admin
  • there you will have path to project on the server
  • on server artfacts are in /var/opt/gitlab/gitlab-rails/shared/artifacts/<project_path_from_web_ui>
  • to delete job.logs run: find /var/opt/gitlab/gitlab-rails/shared/artifacts/<project_path_from_web_ui> -name "job.log" -mtime +60 -delete
    (you can switch “job.log” to anything you deleted on server, “-mtime” is in days, “-delete” flag deletes those files, if you want to just list, then skip it)
  • then you can check integrity by running gitlab-rake gitlab:artifacts:check VERBOSE=1
  • to see result on the web app, you have to run some code in gitlab-rails console
    sudo gitlab-rails console
::Ci::JobArtifact.find_each do |artifact|
  next if artifact.file.filename != "job.log"                 
  next if artifact.file.file.exists?                          
  artifacts_deleted += 1
  puts "#{}  #{artifact.file.path} is missing."    
puts "Count of identified/destroyed invalid references: #{artifacts_deleted}" 

After that, exit from console and delete cache or restart gitlab and you will see results.


Some more scripts and examples are documented in Automate storage management | GitLab and Storage management automation resources

1 Like

I’d like to point out that this only makes the cron job run every minute. It does not affect how long artifacts are kept for. That a different setting altogether. If a certain artifact is flagged to be kept forever, it will stick around.