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
Jérome Perrin
gitlab-ce
Commits
f7d35234
Commit
f7d35234
authored
Feb 28, 2017
by
Tomasz Maczukin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add artifacts downloading API
parent
c2eb5476
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
65 additions
and
0 deletions
+65
-0
lib/api/runner.rb
lib/api/runner.rb
+25
-0
spec/requests/api/runner_spec.rb
spec/requests/api/runner_spec.rb
+40
-0
No files found.
lib/api/runner.rb
View file @
f7d35234
...
...
@@ -221,6 +221,31 @@ module API
render_validation_error!
(
job
)
end
end
desc
'Download the artifacts file for job'
do
http_codes
[[
200
,
'Upload allowed'
],
[
403
,
'Forbidden'
],
[
404
,
'Artifact not found'
]]
end
params
do
requires
:id
,
type:
Fixnum
,
desc:
%q(Job's ID)
optional
:token
,
type:
String
,
desc:
%q(Job's authentication token)
end
get
'/:id/artifacts'
do
job
=
Ci
::
Build
.
find_by_id
(
params
[
:id
])
authenticate_job!
(
job
)
artifacts_file
=
job
.
artifacts_file
unless
artifacts_file
.
file_storage?
return
redirect_to
job
.
artifacts_file
.
url
end
unless
artifacts_file
.
exists?
not_found!
end
present_file!
(
artifacts_file
.
path
,
artifacts_file
.
filename
)
end
end
end
end
spec/requests/api/runner_spec.rb
View file @
f7d35234
...
...
@@ -895,6 +895,46 @@ describe API::Runner do
post
api
(
"/jobs/
#{
job
.
id
}
/artifacts"
),
params
,
headers
end
end
describe
'GET /api/v4/jobs/:id/artifacts'
do
let
(
:token
)
{
job
.
token
}
before
{
download_artifact
}
context
'when job has artifacts'
do
let
(
:job
)
{
create
(
:ci_build
,
:artifacts
)
}
let
(
:download_headers
)
do
{
'Content-Transfer-Encoding'
=>
'binary'
,
'Content-Disposition'
=>
'attachment; filename=ci_build_artifacts.zip'
}
end
context
'when using job token'
do
it
'download artifacts'
do
expect
(
response
).
to
have_http_status
(
200
)
expect
(
response
.
headers
).
to
include
download_headers
end
end
context
'when using runnners token'
do
let
(
:token
)
{
job
.
project
.
runners_token
}
it
'responds with forbidden'
do
expect
(
response
).
to
have_http_status
(
403
)
end
end
end
context
'when job does not has artifacts'
do
it
'responds with not found'
do
expect
(
response
).
to
have_http_status
(
404
)
end
end
def
download_artifact
(
params
=
{},
request_headers
=
headers
)
params
=
params
.
merge
(
token:
token
)
get
api
(
"/jobs/
#{
job
.
id
}
/artifacts"
),
params
,
request_headers
end
end
end
end
end
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