debian-mirror-gitlab/lib/api/job_artifacts.rb

142 lines
4.5 KiB
Ruby
Raw Normal View History

2018-12-05 23:21:45 +05:30
# frozen_string_literal: true
2018-03-17 18:26:18 +05:30
module API
2021-01-03 14:25:43 +05:30
class JobArtifacts < ::API::Base
2018-03-17 18:26:18 +05:30
before { authenticate_non_get! }
2021-01-29 00:20:46 +05:30
feature_category :continuous_integration
2018-03-27 19:54:05 +05:30
# EE::API::JobArtifacts would override the following helpers
helpers do
def authorize_download_artifacts!
authorize_read_builds!
end
end
2021-06-08 01:23:25 +05:30
prepend_mod_with('API::JobArtifacts') # rubocop: disable Cop/InjectEnterpriseEditionModule
2019-12-04 20:38:33 +05:30
2018-03-17 18:26:18 +05:30
params do
requires :id, type: String, desc: 'The ID of a project'
end
2019-02-15 15:39:39 +05:30
resource :projects, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do
2018-03-27 19:54:05 +05:30
desc 'Download the artifacts archive from a job' do
2018-03-17 18:26:18 +05:30
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-27 19:54:05 +05:30
route_setting :authentication, job_token_allowed: true
2018-03-17 18:26:18 +05:30
get ':id/jobs/artifacts/:ref_name/download',
requirements: { ref_name: /.+/ } do
2018-03-27 19:54:05 +05:30
authorize_download_artifacts!
2018-03-17 18:26:18 +05:30
2019-10-12 21:52:04 +05:30
latest_build = user_project.latest_successful_build_for_ref!(params[:job], params[:ref_name])
2021-03-08 18:12:59 +05:30
authorize_read_job_artifacts!(latest_build)
2018-03-17 18:26:18 +05:30
2018-05-09 12:01:36 +05:30
present_carrierwave_file!(latest_build.artifacts_file)
2018-03-17 18:26:18 +05:30
end
2019-02-15 15:39:39 +05:30
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
2021-04-17 20:07:23 +05:30
route_setting :authentication, job_token_allowed: true
2019-02-15 15:39:39 +05:30
get ':id/jobs/artifacts/:ref_name/raw/*artifact_path',
format: false,
requirements: { ref_name: /.+/ } do
authorize_download_artifacts!
2019-10-12 21:52:04 +05:30
build = user_project.latest_successful_build_for_ref!(params[:job], params[:ref_name])
2021-03-08 18:12:59 +05:30
authorize_read_job_artifacts!(build)
2019-02-15 15:39:39 +05:30
path = Gitlab::Ci::Build::Artifacts::Path
.new(params[:artifact_path])
bad_request! unless path.valid?
2020-05-24 23:13:21 +05:30
send_artifacts_entry(build.artifacts_file, path)
2019-02-15 15:39:39 +05:30
end
2018-03-27 19:54:05 +05:30
desc 'Download the artifacts archive from a job' do
2018-03-17 18:26:18 +05:30
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-27 19:54:05 +05:30
route_setting :authentication, job_token_allowed: true
2018-03-17 18:26:18 +05:30
get ':id/jobs/:job_id/artifacts' do
2018-03-27 19:54:05 +05:30
authorize_download_artifacts!
2018-03-17 18:26:18 +05:30
build = find_build!(params[:job_id])
2021-03-08 18:12:59 +05:30
authorize_read_job_artifacts!(build)
2018-03-17 18:26:18 +05:30
2018-05-09 12:01:36 +05:30
present_carrierwave_file!(build.artifacts_file)
2018-03-17 18:26:18 +05:30
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
2021-04-17 20:07:23 +05:30
route_setting :authentication, job_token_allowed: true
2018-03-17 18:26:18 +05:30
get ':id/jobs/:job_id/artifacts/*artifact_path', format: false do
2021-03-08 18:12:59 +05:30
authorize_download_artifacts!
2018-03-17 18:26:18 +05:30
build = find_build!(params[:job_id])
2021-03-08 18:12:59 +05:30
authorize_read_job_artifacts!(build)
2021-04-17 20:07:23 +05:30
not_found! unless build.available_artifacts?
2018-03-17 18:26:18 +05:30
path = Gitlab::Ci::Build::Artifacts::Path
.new(params[:artifact_path])
2019-02-15 15:39:39 +05:30
2018-03-17 18:26:18 +05:30
bad_request! unless path.valid?
2020-05-24 23:13:21 +05:30
send_artifacts_entry(build.artifacts_file, path)
2018-03-17 18:26:18 +05:30
end
desc 'Keep the artifacts to prevent them from being deleted' do
2020-10-24 23:57:45 +05:30
success ::API::Entities::Ci::Job
2018-03-17 18:26:18 +05:30
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-10-15 14:42:47 +05:30
break not_found!(build) unless build.artifacts?
2018-03-17 18:26:18 +05:30
build.keep_artifacts!
status 200
2020-10-24 23:57:45 +05:30
present build, with: ::API::Entities::Ci::Job
2018-03-17 18:26:18 +05:30
end
2019-07-07 11:18:12 +05:30
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
2018-03-17 18:26:18 +05:30
end
end
end