Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Léo-Paul Géneau
gitlab-ce
Commits
f3f1ad39
Commit
f3f1ad39
authored
Sep 04, 2017
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add API endpoint for downloading single job artifact
parent
ebbbc7ef
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
76 additions
and
0 deletions
+76
-0
lib/api/jobs.rb
lib/api/jobs.rb
+19
-0
spec/requests/api/jobs_spec.rb
spec/requests/api/jobs_spec.rb
+57
-0
No files found.
lib/api/jobs.rb
View file @
f3f1ad39
...
...
@@ -85,6 +85,25 @@ module API
present_artifacts!
(
build
.
artifacts_file
)
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
=
get_build!
(
params
[
:job_id
])
not_found!
unless
build
.
artifacts?
entry
=
build
.
artifacts_metadata_entry
(
params
[
:artifact_path
])
not_found!
unless
entry
.
exists?
Gitlab
::
Workhorse
.
send_artifacts_entry
(
build
,
entry
)
end
desc
'Download the artifacts file from a job'
do
detail
'This feature was introduced in GitLab 8.10'
end
...
...
spec/requests/api/jobs_spec.rb
View file @
f3f1ad39
...
...
@@ -188,6 +188,63 @@ describe API::Jobs do
end
end
describe
'GET /projects/:id/jobs/:job_id/artifacts/:artifact_path'
do
context
'when job has artifacts'
do
let
(
:job
)
{
create
(
:ci_build
,
:artifacts
,
pipeline:
pipeline
)
}
let
(
:artifact
)
do
'other_artifacts_0.1.2/another-subdirectory/banana_sample.gif'
end
context
'when user is not unauthorized'
do
let
(
:api_user
)
{
nil
}
it
'does not return specific job artifacts'
do
get_artifact_file
(
artifact
)
expect
(
response
).
to
have_http_status
(
401
)
end
end
context
'when user is authorized'
do
it
'returns a specific artifact file for a valid path'
do
expect
(
Gitlab
::
Workhorse
)
.
to
receive
(
:send_artifacts_entry
)
.
and_call_original
get_artifact_file
(
artifact
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
response
.
body
)
.
to
include
'Gitlab-Workhorse-Send-Data'
,
'artifacts-entry'
expect
(
response
.
headers
)
.
to
include
(
'Content-Type'
=>
'application/json'
)
end
end
context
'when request path is invalid'
do
it
'does not find artifact file'
do
get_artifact_file
(
'invalid/path'
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
end
context
'when job does not have artifacts'
do
it
'does not return job artifact file'
do
get_artifact_file
(
'some/artifact'
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
def
get_artifact_file
(
artifact_path
)
get
api
(
"/projects/
#{
project
.
id
}
/jobs/
#{
job
.
id
}
/"
\
"artifacts/
#{
artifact_path
}
"
,
api_user
)
end
end
describe
'GET /projects/:id/jobs/:job_id/artifacts'
do
before
do
get
api
(
"/projects/
#{
project
.
id
}
/jobs/
#{
job
.
id
}
/artifacts"
,
api_user
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment