2021-07-20 17:09:52 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module API
|
|
|
|
module Ci
|
|
|
|
class JobArtifacts < ::API::Base
|
2022-05-30 08:08:23 -04:00
|
|
|
helpers ::API::Helpers::ProjectStatsRefreshConflictsHelpers
|
|
|
|
|
2021-07-20 17:09:52 -04:00
|
|
|
before { authenticate_non_get! }
|
|
|
|
|
|
|
|
feature_category :build_artifacts
|
|
|
|
|
|
|
|
# EE::API::Ci::JobArtifacts would override the following helpers
|
|
|
|
helpers do
|
|
|
|
def authorize_download_artifacts!
|
|
|
|
authorize_read_builds!
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
prepend_mod_with('API::Ci::JobArtifacts') # rubocop: disable Cop/InjectEnterpriseEditionModule
|
|
|
|
|
|
|
|
params do
|
|
|
|
requires :id, type: String, desc: 'The ID of a project'
|
|
|
|
end
|
|
|
|
resource :projects, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do
|
|
|
|
desc 'Download the artifacts archive from a job' do
|
|
|
|
detail 'This feature was introduced in GitLab 8.10'
|
|
|
|
end
|
|
|
|
params do
|
|
|
|
requires :ref_name, type: String, desc: 'The ref from repository'
|
|
|
|
requires :job, type: String, desc: 'The name for the job'
|
|
|
|
end
|
|
|
|
route_setting :authentication, job_token_allowed: true
|
2022-03-23 05:07:30 -04:00
|
|
|
get ':id/jobs/artifacts/:ref_name/download', urgency: :low,
|
2021-07-20 17:09:52 -04:00
|
|
|
requirements: { ref_name: /.+/ } do
|
|
|
|
authorize_download_artifacts!
|
|
|
|
|
|
|
|
latest_build = user_project.latest_successful_build_for_ref!(params[:job], params[:ref_name])
|
|
|
|
authorize_read_job_artifacts!(latest_build)
|
|
|
|
|
2022-06-15 11:09:20 -04:00
|
|
|
present_artifacts_file!(latest_build.artifacts_file)
|
2021-07-20 17:09:52 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
desc 'Download a specific file from artifacts archive from a ref' do
|
|
|
|
detail 'This feature was introduced in GitLab 11.5'
|
|
|
|
end
|
|
|
|
params do
|
|
|
|
requires :ref_name, type: String, desc: 'The ref from repository'
|
|
|
|
requires :job, type: String, desc: 'The name for the job'
|
|
|
|
requires :artifact_path, type: String, desc: 'Artifact path'
|
|
|
|
end
|
|
|
|
route_setting :authentication, job_token_allowed: true
|
2022-02-04 10:15:34 -05:00
|
|
|
get ':id/jobs/artifacts/:ref_name/raw/*artifact_path', urgency: :low,
|
2021-07-20 17:09:52 -04:00
|
|
|
format: false,
|
|
|
|
requirements: { ref_name: /.+/ } do
|
|
|
|
authorize_download_artifacts!
|
|
|
|
|
|
|
|
build = user_project.latest_successful_build_for_ref!(params[:job], params[:ref_name])
|
|
|
|
authorize_read_job_artifacts!(build)
|
|
|
|
|
|
|
|
path = Gitlab::Ci::Build::Artifacts::Path
|
|
|
|
.new(params[:artifact_path])
|
|
|
|
|
|
|
|
bad_request! unless path.valid?
|
|
|
|
|
2022-04-12 08:08:50 -04:00
|
|
|
send_artifacts_entry(build.artifacts_file, path)
|
2021-07-20 17:09:52 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
desc 'Download the artifacts archive from a job' do
|
|
|
|
detail 'This feature was introduced in GitLab 8.5'
|
|
|
|
end
|
|
|
|
params do
|
|
|
|
requires :job_id, type: Integer, desc: 'The ID of a job'
|
|
|
|
end
|
|
|
|
route_setting :authentication, job_token_allowed: true
|
2022-02-04 10:15:34 -05:00
|
|
|
get ':id/jobs/:job_id/artifacts', urgency: :low do
|
2021-07-20 17:09:52 -04:00
|
|
|
authorize_download_artifacts!
|
|
|
|
|
|
|
|
build = find_build!(params[:job_id])
|
|
|
|
authorize_read_job_artifacts!(build)
|
|
|
|
|
2022-06-15 11:09:20 -04:00
|
|
|
present_artifacts_file!(build.artifacts_file)
|
2021-07-20 17:09:52 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
desc 'Download a specific file from artifacts archive' do
|
|
|
|
detail 'This feature was introduced in GitLab 10.0'
|
|
|
|
end
|
|
|
|
params do
|
|
|
|
requires :job_id, type: Integer, desc: 'The ID of a job'
|
|
|
|
requires :artifact_path, type: String, desc: 'Artifact path'
|
|
|
|
end
|
|
|
|
route_setting :authentication, job_token_allowed: true
|
2022-03-23 05:07:30 -04:00
|
|
|
get ':id/jobs/:job_id/artifacts/*artifact_path', urgency: :low, format: false do
|
2021-07-20 17:09:52 -04:00
|
|
|
authorize_download_artifacts!
|
|
|
|
|
|
|
|
build = find_build!(params[:job_id])
|
|
|
|
authorize_read_job_artifacts!(build)
|
|
|
|
|
|
|
|
not_found! unless build.available_artifacts?
|
|
|
|
|
|
|
|
path = Gitlab::Ci::Build::Artifacts::Path
|
|
|
|
.new(params[:artifact_path])
|
|
|
|
|
|
|
|
bad_request! unless path.valid?
|
|
|
|
|
2022-04-05 14:09:00 -04:00
|
|
|
# This endpoint is being used for Artifact Browser feature that renders the content via pages.
|
|
|
|
# Since Content-Type is controlled by Rails and Workhorse, if a wrong
|
|
|
|
# content-type is sent, it could cause a regression on pages rendering.
|
|
|
|
# See https://gitlab.com/gitlab-org/gitlab/-/issues/357078 for more information.
|
|
|
|
legacy_send_artifacts_entry(build.artifacts_file, path)
|
2021-07-20 17:09:52 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
desc 'Keep the artifacts to prevent them from being deleted' do
|
|
|
|
success ::API::Entities::Ci::Job
|
|
|
|
end
|
|
|
|
params do
|
|
|
|
requires :job_id, type: Integer, desc: 'The ID of a job'
|
|
|
|
end
|
|
|
|
post ':id/jobs/:job_id/artifacts/keep' do
|
|
|
|
authorize_update_builds!
|
|
|
|
|
|
|
|
build = find_build!(params[:job_id])
|
|
|
|
authorize!(:update_build, build)
|
|
|
|
break not_found!(build) unless build.artifacts?
|
|
|
|
|
|
|
|
build.keep_artifacts!
|
|
|
|
|
|
|
|
status 200
|
|
|
|
present build, with: ::API::Entities::Ci::Job
|
|
|
|
end
|
|
|
|
|
|
|
|
desc 'Delete the artifacts files from a job' do
|
|
|
|
detail 'This feature was introduced in GitLab 11.9'
|
|
|
|
end
|
|
|
|
params do
|
|
|
|
requires :job_id, type: Integer, desc: 'The ID of a job'
|
|
|
|
end
|
|
|
|
delete ':id/jobs/:job_id/artifacts' do
|
|
|
|
authorize_destroy_artifacts!
|
|
|
|
build = find_build!(params[:job_id])
|
|
|
|
authorize!(:destroy_artifacts, build)
|
|
|
|
|
2022-05-30 08:08:23 -04:00
|
|
|
reject_if_build_artifacts_size_refreshing!(build.project)
|
|
|
|
|
2021-07-20 17:09:52 -04:00
|
|
|
build.erase_erasable_artifacts!
|
|
|
|
|
|
|
|
status :no_content
|
|
|
|
end
|
2022-01-13 10:14:46 -05:00
|
|
|
|
|
|
|
desc 'Expire the artifacts files from a project'
|
|
|
|
delete ':id/artifacts' do
|
|
|
|
authorize_destroy_artifacts!
|
|
|
|
|
2022-05-30 08:08:23 -04:00
|
|
|
reject_if_build_artifacts_size_refreshing!(user_project)
|
|
|
|
|
2022-01-13 10:14:46 -05:00
|
|
|
::Ci::JobArtifacts::DeleteProjectArtifactsService.new(project: user_project).execute
|
|
|
|
|
|
|
|
accepted!
|
|
|
|
end
|
2021-07-20 17:09:52 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|