summaryrefslogtreecommitdiff
path: root/lib/api/job_artifacts.rb
diff options
context:
space:
mode:
authorSteve Azzopardi <steveazz@outlook.com>2018-12-04 11:50:01 +0100
committerSteve Azzopardi <steveazz@outlook.com>2018-12-07 15:33:30 +0100
commit401f65c43aa12aa712daa8ddfb00a4fb731541c8 (patch)
treea47285f34754b7339225a1baf9db2caa0ea7b7bf /lib/api/job_artifacts.rb
parent62d971129da99936a3cdc04f3740d26f16a0c7a6 (diff)
downloadgitlab-ce-401f65c43aa12aa712daa8ddfb00a4fb731541c8.tar.gz
Add endpoint to download single artifact by ref
Add a new endpoint `projects/:id/jobs/artifacts/:ref_name/raw/*artifact_path?job=name` which is the close the web URL for consistency sake. This endpoint can be used to download a single file from artifacts for the specified ref and job. closes https://gitlab.com/gitlab-org/gitlab-ce/issues/54626
Diffstat (limited to 'lib/api/job_artifacts.rb')
-rw-r--r--lib/api/job_artifacts.rb24
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/api/job_artifacts.rb b/lib/api/job_artifacts.rb
index 7c2d8ff11bf..a4068a200b3 100644
--- a/lib/api/job_artifacts.rb
+++ b/lib/api/job_artifacts.rb
@@ -35,6 +35,29 @@ module API
end
# rubocop: enable CodeReuse/ActiveRecord
+ 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!
+
+ build = user_project.latest_successful_build_for(params[:job], params[:ref_name])
+
+ path = Gitlab::Ci::Build::Artifacts::Path
+ .new(params[:artifact_path])
+
+ bad_request! unless path.valid?
+
+ send_artifacts_entry(build, path)
+ end
+
desc 'Download the artifacts archive from a job' do
detail 'This feature was introduced in GitLab 8.5'
end
@@ -65,6 +88,7 @@ module API
path = Gitlab::Ci::Build::Artifacts::Path
.new(params[:artifact_path])
+
bad_request! unless path.valid?
send_artifacts_entry(build, path)