Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--changelogs/unreleased/ignore-writing-trace-if-it-already-archived.yml5
-rw-r--r--lib/api/runner.rb5
-rw-r--r--spec/requests/api/runner_spec.rb15
3 files changed, 23 insertions, 2 deletions
diff --git a/changelogs/unreleased/ignore-writing-trace-if-it-already-archived.yml b/changelogs/unreleased/ignore-writing-trace-if-it-already-archived.yml
new file mode 100644
index 00000000000..5c342e2a131
--- /dev/null
+++ b/changelogs/unreleased/ignore-writing-trace-if-it-already-archived.yml
@@ -0,0 +1,5 @@
+---
+title: Disallow updating job status if the job is not running
+merge_request: 19101
+author:
+type: fixed
diff --git a/lib/api/runner.rb b/lib/api/runner.rb
index a7f1cb1131f..5b7ae89440c 100644
--- a/lib/api/runner.rb
+++ b/lib/api/runner.rb
@@ -123,6 +123,7 @@ module API
end
put '/:id' do
job = authenticate_job!
+ forbidden!('Job is not running') unless job.running?
job.trace.set(params[:trace]) if params[:trace]
@@ -131,9 +132,9 @@ module API
case params[:state].to_s
when 'success'
- job.success
+ job.success!
when 'failed'
- job.drop(params[:failure_reason] || :unknown_failure)
+ job.drop!(params[:failure_reason] || :unknown_failure)
end
end
diff --git a/spec/requests/api/runner_spec.rb b/spec/requests/api/runner_spec.rb
index efb9bddde44..827c6dd4af1 100644
--- a/spec/requests/api/runner_spec.rb
+++ b/spec/requests/api/runner_spec.rb
@@ -830,6 +830,21 @@ describe API::Runner, :clean_gitlab_redis_shared_state do
end
end
+ context 'when job has already been finished' do
+ before do
+ job.trace.set('Job failed')
+ job.drop!(:script_failure)
+ end
+
+ it 'does not update job status and job trace' do
+ update_job(state: 'success', trace: 'BUILD TRACE UPDATED')
+
+ expect(response).to have_gitlab_http_status(403)
+ expect(job.trace.raw).to eq 'Job failed'
+ expect(job).to be_failed
+ end
+ end
+
def update_job(token = job.token, **params)
new_params = params.merge(token: token)
put api("/jobs/#{job.id}"), new_params