2018-09-29 22:34:47 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-09-06 09:20:12 +00:00
|
|
|
module API
|
|
|
|
class JobArtifacts < Grape::API
|
|
|
|
before { authenticate_non_get! }
|
|
|
|
|
2018-03-06 11:30:13 +00:00
|
|
|
# EE::API::JobArtifacts would override the following helpers
|
|
|
|
helpers do
|
|
|
|
def authorize_download_artifacts!
|
|
|
|
authorize_read_builds!
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-09-13 13:26:31 +00:00
|
|
|
prepend_if_ee('EE::API::JobArtifacts') # rubocop: disable Cop/InjectEnterpriseEditionModule
|
|
|
|
|
2017-09-06 09:20:12 +00:00
|
|
|
params do
|
|
|
|
requires :id, type: String, desc: 'The ID of a project'
|
|
|
|
end
|
2018-11-08 12:18:17 +00:00
|
|
|
resource :projects, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do
|
2018-03-06 11:30:13 +00:00
|
|
|
desc 'Download the artifacts archive from a job' do
|
2017-09-06 09:20:12 +00:00
|
|
|
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
|
2018-03-06 11:30:13 +00:00
|
|
|
route_setting :authentication, job_token_allowed: true
|
2017-09-06 09:20:12 +00:00
|
|
|
get ':id/jobs/artifacts/:ref_name/download',
|
|
|
|
requirements: { ref_name: /.+/ } do
|
2018-03-06 11:30:13 +00:00
|
|
|
authorize_download_artifacts!
|
2017-09-06 09:20:12 +00:00
|
|
|
|
2019-07-23 19:29:12 +00:00
|
|
|
latest_build = user_project.latest_successful_build_for_ref!(params[:job], params[:ref_name])
|
2017-09-06 09:20:12 +00:00
|
|
|
|
2018-03-09 14:16:06 +00:00
|
|
|
present_carrierwave_file!(latest_build.artifacts_file)
|
2017-09-06 09:20:12 +00:00
|
|
|
end
|
|
|
|
|
2018-12-04 10:50:01 +00:00
|
|
|
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
|
|
|
|
get ':id/jobs/artifacts/:ref_name/raw/*artifact_path',
|
|
|
|
format: false,
|
|
|
|
requirements: { ref_name: /.+/ } do
|
|
|
|
authorize_download_artifacts!
|
|
|
|
|
2019-07-23 19:29:12 +00:00
|
|
|
build = user_project.latest_successful_build_for_ref!(params[:job], params[:ref_name])
|
2018-12-04 10:50:01 +00:00
|
|
|
|
|
|
|
path = Gitlab::Ci::Build::Artifacts::Path
|
|
|
|
.new(params[:artifact_path])
|
|
|
|
|
|
|
|
bad_request! unless path.valid?
|
|
|
|
|
|
|
|
send_artifacts_entry(build, path)
|
|
|
|
end
|
|
|
|
|
2018-03-06 11:30:13 +00:00
|
|
|
desc 'Download the artifacts archive from a job' do
|
2017-09-06 09:20:12 +00:00
|
|
|
detail 'This feature was introduced in GitLab 8.5'
|
|
|
|
end
|
|
|
|
params do
|
|
|
|
requires :job_id, type: Integer, desc: 'The ID of a job'
|
|
|
|
end
|
2018-03-06 11:30:13 +00:00
|
|
|
route_setting :authentication, job_token_allowed: true
|
2017-09-06 09:20:12 +00:00
|
|
|
get ':id/jobs/:job_id/artifacts' do
|
2018-03-06 11:30:13 +00:00
|
|
|
authorize_download_artifacts!
|
2017-09-06 09:20:12 +00:00
|
|
|
|
|
|
|
build = find_build!(params[:job_id])
|
|
|
|
|
2018-03-09 14:16:06 +00:00
|
|
|
present_carrierwave_file!(build.artifacts_file)
|
2017-09-06 09:20:12 +00: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
|
|
|
|
get ':id/jobs/:job_id/artifacts/*artifact_path', format: false do
|
|
|
|
authorize_read_builds!
|
|
|
|
|
|
|
|
build = find_build!(params[:job_id])
|
|
|
|
not_found! unless build.artifacts?
|
|
|
|
|
|
|
|
path = Gitlab::Ci::Build::Artifacts::Path
|
|
|
|
.new(params[:artifact_path])
|
2018-12-04 10:50:01 +00:00
|
|
|
|
2017-09-06 09:31:08 +00:00
|
|
|
bad_request! unless path.valid?
|
2017-09-06 09:20:12 +00:00
|
|
|
|
|
|
|
send_artifacts_entry(build, path)
|
|
|
|
end
|
|
|
|
|
|
|
|
desc 'Keep the artifacts to prevent them from being deleted' do
|
|
|
|
success Entities::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)
|
2018-04-18 09:19:40 +00:00
|
|
|
break not_found!(build) unless build.artifacts?
|
2017-09-06 09:20:12 +00:00
|
|
|
|
|
|
|
build.keep_artifacts!
|
|
|
|
|
|
|
|
status 200
|
|
|
|
present build, with: Entities::Job
|
|
|
|
end
|
2019-03-06 11:06:21 +00:00
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
build.erase_erasable_artifacts!
|
|
|
|
|
|
|
|
status :no_content
|
|
|
|
end
|
2017-09-06 09:20:12 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|