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
Tatuya Kamada
gitlab-ce
Commits
d5f7e542
Commit
d5f7e542
authored
Feb 28, 2017
by
Tomasz Maczukin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add job update API
parent
fb8210ad
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
86 additions
and
3 deletions
+86
-3
lib/api/helpers/runner.rb
lib/api/helpers/runner.rb
+10
-1
lib/api/runner.rb
lib/api/runner.rb
+28
-2
spec/requests/api/runner_spec.rb
spec/requests/api/runner_spec.rb
+48
-0
No files found.
lib/api/helpers/runner.rb
View file @
d5f7e542
...
...
@@ -39,13 +39,22 @@ module API
(
Time
.
now
-
current_runner
.
contacted_at
)
>=
contacted_at_max_age
end
def
build
_not_found!
def
job
_not_found!
if
headers
[
'User-Agent'
].
to_s
.
match
(
/gitlab(-ci-multi)?-runner \d+\.\d+\.\d+(~beta\.\d+\.g[0-9a-f]+)? /
)
no_content!
else
not_found!
end
end
def
validate_job!
(
job
)
not_found!
unless
job
yield
if
block_given?
forbidden!
(
'Project has been deleted!'
)
unless
job
.
project
forbidden!
(
'Job has been erased!'
)
if
job
.
erased?
end
end
end
end
lib/api/runner.rb
View file @
d5f7e542
...
...
@@ -66,7 +66,7 @@ module API
if
current_runner
.
is_runner_queue_value_latest?
(
params
[
:last_update
])
header
'X-GitLab-Last-Update'
,
params
[
:last_update
]
Gitlab
::
Metrics
.
add_event
(
:build_not_found_cached
)
return
build
_not_found!
return
job
_not_found!
end
new_update
=
current_runner
.
ensure_runner_queue_value
...
...
@@ -80,7 +80,7 @@ module API
else
Gitlab
::
Metrics
.
add_event
(
:build_not_found
)
header
'X-GitLab-Last-Update'
,
new_update
build
_not_found!
job
_not_found!
end
else
# We received build that is invalid due to concurrency conflict
...
...
@@ -88,6 +88,32 @@ module API
conflict!
end
end
desc
'Updates a job'
do
http_codes
[[
200
,
'Job was updated'
],
[
403
,
'Forbidden'
]]
end
params
do
requires
:token
,
type:
String
,
desc:
%q(Job's authentication token)
requires
:id
,
type:
Fixnum
,
desc:
%q(Job's ID)
optional
:trace
,
type:
String
,
desc:
%q(Job's full trace)
optional
:state
,
type:
String
,
desc:
%q(Job's status: success, failed)
end
put
'/:id'
do
job
=
Ci
::
Build
.
find_by_id
(
params
[
:id
])
authenticate_job!
(
job
)
job
.
update_attributes
(
trace:
params
[
:trace
])
if
params
[
:trace
]
Gitlab
::
Metrics
.
add_event
(
:update_build
,
project:
job
.
project
.
path_with_namespace
)
case
params
[
:state
].
to_s
when
'success'
job
.
success
when
'failed'
job
.
drop
end
end
end
end
end
spec/requests/api/runner_spec.rb
View file @
d5f7e542
...
...
@@ -432,5 +432,53 @@ describe API::Runner do
end
end
end
describe
'PUT /api/v4/jobs/:id'
do
let
(
:job
)
{
create
(
:ci_build
,
:pending
,
:trace
,
pipeline:
pipeline
,
runner_id:
runner
.
id
)
}
before
{
job
.
run!
}
context
'when status is given'
do
it
'mark job as succeeded'
do
update_job
(
state:
'success'
)
expect
(
job
.
reload
.
status
).
to
eq
'success'
end
it
'mark job as failed'
do
update_job
(
state:
'failed'
)
expect
(
job
.
reload
.
status
).
to
eq
'failed'
end
end
context
'when tace is given'
do
it
'updates a running build'
do
update_job
(
trace:
'BUILD TRACE UPDATED'
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
job
.
reload
.
trace
).
to
eq
'BUILD TRACE UPDATED'
end
end
context
'when no trace is given'
do
it
'does not override trace information'
do
update_job
expect
(
job
.
reload
.
trace
).
to
eq
'BUILD TRACE'
end
end
context
'when job has been erased'
do
let
(
:job
)
{
create
(
:ci_build
,
runner_id:
runner
.
id
,
erased_at:
Time
.
now
)
}
it
'responds with forbidden'
do
update_job
expect
(
response
).
to
have_http_status
(
403
)
end
end
def
update_job
(
token
=
job
.
token
,
**
params
)
new_params
=
params
.
merge
(
token:
token
)
put
api
(
"/jobs/
#{
job
.
id
}
"
),
new_params
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