Remove all artifact (no expire options)

This was helpful: Jobs artifacts administration | GitLab

As there described, getting the top 20 projects with large space usage

$ gitlab-rails console
include ActionView::Helpers::NumberHelper
ProjectStatistics.order(build_artifacts_size: :desc).limit(20).each do |s|
  puts "#{number_to_human_size(s.build_artifacts_size)} \t #{s.project.full_path}"
end

Then for each project:

project = Project.find_by_full_path('path/to/project')
builds_with_artifacts =  project.builds.with_downloadable_artifacts
builds_to_clear = builds_with_artifacts.where("finished_at < ?", 1.week.ago)
builds_to_clear.find_each do |build|
  build.artifacts_expire_at = Time.now
  build.erase_erasable_artifacts!
end

Other variations are on the same manual.

For some reason, API call didn’t work for me as expected:

curl --request DELETE --header "PRIVATE-TOKEN: <token>" "https://gitlab.example.com/api/v4/projects/<project_id>/artifacts"

Although I got response 202 which shall be good, the same space usage for the project was after this call.

1 Like