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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

219 lines
8.1 KiB
Ruby
Raw Normal View History

2021-10-27 15:23:28 +05:30
# frozen_string_literal: true
module API
module Ci
class JobArtifacts < ::API::Base
2022-07-23 23:45:48 +05:30
helpers ::API::Helpers::ProjectStatsRefreshConflictsHelpers
2021-10-27 15:23:28 +05:30
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
params do
2023-01-13 00:05:48 +05:30
requires :id, types: [String, Integer], desc: 'The ID or URL-encoded path of the project'
2021-10-27 15:23:28 +05:30
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'
2023-03-04 22:38:38 +05:30
failure [
{ code: 401, message: 'Unauthorized' },
{ code: 403, message: 'Forbidden' },
{ code: 404, message: 'Not found' }
]
2021-10-27 15:23:28 +05:30
end
params do
2023-03-04 22:38:38 +05:30
requires :ref_name, type: String,
desc: 'Branch or tag name in repository. `HEAD` or `SHA` references are not supported.'
requires :job, type: String, desc: 'The name of the job.'
optional :job_token, type: String,
desc: 'To be used with triggers for multi-project pipelines, ' \
'available only on Premium and Ultimate tiers.'
2021-10-27 15:23:28 +05:30
end
route_setting :authentication, job_token_allowed: true
2022-08-27 11:52:29 +05:30
get ':id/jobs/artifacts/:ref_name/download',
urgency: :low,
requirements: { ref_name: /.+/ } do
authorize_download_artifacts!
2021-10-27 15:23:28 +05:30
2022-08-27 11:52:29 +05:30
latest_build = user_project.latest_successful_build_for_ref!(params[:job], params[:ref_name])
authorize_read_job_artifacts!(latest_build)
2021-10-27 15:23:28 +05:30
2023-01-13 00:05:48 +05:30
present_artifacts_file!(latest_build.artifacts_file)
2022-08-27 11:52:29 +05:30
end
2021-10-27 15:23:28 +05:30
desc 'Download a specific file from artifacts archive from a ref' do
detail 'This feature was introduced in GitLab 11.5'
2023-03-04 22:38:38 +05:30
failure [
{ code: 400, message: 'Bad request' },
{ code: 401, message: 'Unauthorized' },
{ code: 403, message: 'Forbidden' },
{ code: 404, message: 'Not found' }
]
2021-10-27 15:23:28 +05:30
end
params do
2023-03-04 22:38:38 +05:30
requires :ref_name, type: String,
desc: 'Branch or tag name in repository. `HEAD` or `SHA` references are not supported.'
requires :job, type: String, desc: 'The name of the job.'
requires :artifact_path, type: String, desc: 'Path to a file inside the artifacts archive.'
optional :job_token, type: String,
desc: 'To be used with triggers for multi-project pipelines, ' \
'available only on Premium and Ultimate tiers.'
2021-10-27 15:23:28 +05:30
end
route_setting :authentication, job_token_allowed: true
2022-08-27 11:52:29 +05:30
get ':id/jobs/artifacts/:ref_name/raw/*artifact_path',
urgency: :low,
format: false,
requirements: { ref_name: /.+/ } do
authorize_download_artifacts!
2021-10-27 15:23:28 +05:30
2022-08-27 11:52:29 +05:30
build = user_project.latest_successful_build_for_ref!(params[:job], params[:ref_name])
authorize_read_job_artifacts!(build)
2021-10-27 15:23:28 +05:30
2022-08-27 11:52:29 +05:30
path = Gitlab::Ci::Build::Artifacts::Path
.new(params[:artifact_path])
2021-10-27 15:23:28 +05:30
2022-08-27 11:52:29 +05:30
bad_request! unless path.valid?
2021-10-27 15:23:28 +05:30
2022-08-27 11:52:29 +05:30
send_artifacts_entry(build.artifacts_file, path)
end
2021-10-27 15:23:28 +05:30
desc 'Download the artifacts archive from a job' do
detail 'This feature was introduced in GitLab 8.5'
2023-03-04 22:38:38 +05:30
failure [
{ code: 401, message: 'Unauthorized' },
{ code: 403, message: 'Forbidden' },
{ code: 404, message: 'Not found' }
]
2021-10-27 15:23:28 +05:30
end
params do
requires :job_id, type: Integer, desc: 'The ID of a job'
2023-03-04 22:38:38 +05:30
optional :job_token, type: String,
desc: 'To be used with triggers for multi-project pipelines, ' \
'available only on Premium and Ultimate tiers.'
2021-10-27 15:23:28 +05:30
end
route_setting :authentication, job_token_allowed: true
2022-04-04 11:22:00 +05:30
get ':id/jobs/:job_id/artifacts', urgency: :low do
2021-10-27 15:23:28 +05:30
authorize_download_artifacts!
build = find_build!(params[:job_id])
authorize_read_job_artifacts!(build)
2023-01-13 00:05:48 +05:30
present_artifacts_file!(build.artifacts_file)
2021-10-27 15:23:28 +05:30
end
desc 'Download a specific file from artifacts archive' do
detail 'This feature was introduced in GitLab 10.0'
2023-03-04 22:38:38 +05:30
failure [
{ code: 400, message: 'Bad request' },
{ code: 401, message: 'Unauthorized' },
{ code: 403, message: 'Forbidden' },
{ code: 404, message: 'Not found' }
]
2021-10-27 15:23:28 +05:30
end
params do
requires :job_id, type: Integer, desc: 'The ID of a job'
2023-03-04 22:38:38 +05:30
requires :artifact_path, type: String, desc: 'Path to a file inside the artifacts archive.'
optional :job_token, type: String,
desc: 'To be used with triggers for multi-project pipelines, ' \
'available only on Premium and Ultimate tiers.'
2021-10-27 15:23:28 +05:30
end
route_setting :authentication, job_token_allowed: true
2022-06-21 17:19:12 +05:30
get ':id/jobs/:job_id/artifacts/*artifact_path', urgency: :low, format: false do
2021-10-27 15:23:28 +05:30
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-06-21 17:19:12 +05:30
# 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-10-27 15:23:28 +05:30
end
desc 'Keep the artifacts to prevent them from being deleted' do
success ::API::Entities::Ci::Job
2023-03-04 22:38:38 +05:30
failure [
{ code: 401, message: 'Unauthorized' },
{ code: 403, message: 'Forbidden' },
{ code: 404, message: 'Not found' }
]
2021-10-27 15:23:28 +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)
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'
2023-03-04 22:38:38 +05:30
success code: 204
failure [
{ code: 401, message: 'Unauthorized' },
{ code: 403, message: 'Forbidden' },
{ code: 409, message: 'Conflict' }
]
2021-10-27 15:23:28 +05:30
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-07-23 23:45:48 +05:30
reject_if_build_artifacts_size_refreshing!(build.project)
2022-10-11 01:57:18 +05:30
::Ci::JobArtifacts::DeleteService.new(build).execute
2021-10-27 15:23:28 +05:30
status :no_content
end
2022-03-02 08:16:31 +05:30
2023-03-04 22:38:38 +05:30
desc 'Expire the artifacts files from a project' do
success code: 202
failure [
{ code: 401, message: 'Unauthorized' },
{ code: 403, message: 'Forbidden' },
{ code: 409, message: 'Conflict' }
]
end
2022-03-02 08:16:31 +05:30
delete ':id/artifacts' do
authorize_destroy_artifacts!
2022-07-23 23:45:48 +05:30
reject_if_build_artifacts_size_refreshing!(user_project)
2022-03-02 08:16:31 +05:30
::Ci::JobArtifacts::DeleteProjectArtifactsService.new(project: user_project).execute
accepted!
end
2021-10-27 15:23:28 +05:30
end
end
end
end
2023-03-04 22:38:38 +05:30
API::Ci::JobArtifacts.prepend_mod