diff options
Diffstat (limited to 'lib/api')
-rw-r--r-- | lib/api/helpers/runner.rb | 11 | ||||
-rw-r--r-- | lib/api/runner.rb | 30 |
2 files changed, 38 insertions, 3 deletions
diff --git a/lib/api/helpers/runner.rb b/lib/api/helpers/runner.rb index 8204adbcfe5..15eb6b932ed 100644 --- a/lib/api/helpers/runner.rb +++ b/lib/api/helpers/runner.rb @@ -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 diff --git a/lib/api/runner.rb b/lib/api/runner.rb index ada1073c8dc..b57fbdabab9 100644 --- a/lib/api/runner.rb +++ b/lib/api/runner.rb @@ -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 |