Commit 68f6c61c authored by Shinya Maeda's avatar Shinya Maeda

- Allow runner API to pass failure_reason

- Fix spec
parent 1d7c0390
...@@ -42,7 +42,7 @@ class CommitStatus < ActiveRecord::Base ...@@ -42,7 +42,7 @@ class CommitStatus < ActiveRecord::Base
unknown_failure: nil, unknown_failure: nil,
job_failure: 1, job_failure: 1,
api_failure: 2, api_failure: 2,
stuck_or_timeout_failure: 3, stuck_or_timeout_failure: 3
} }
state_machine :status do state_machine :status do
......
---
title: Implement `failure_reason` on `ci_builds`
merge_request: 13937
author:
type: added
...@@ -114,6 +114,8 @@ module API ...@@ -114,6 +114,8 @@ module API
requires :id, type: Integer, desc: %q(Job's ID) requires :id, type: Integer, desc: %q(Job's ID)
optional :trace, type: String, desc: %q(Job's full trace) optional :trace, type: String, desc: %q(Job's full trace)
optional :state, type: String, desc: %q(Job's status: success, failed) optional :state, type: String, desc: %q(Job's status: success, failed)
optional :failure_reason, type: String, values: CommitStatus.failure_reasons.keys,
desc: %q(Job's failure_reason)
end end
put '/:id' do put '/:id' do
job = authenticate_job! job = authenticate_job!
...@@ -127,7 +129,11 @@ module API ...@@ -127,7 +129,11 @@ module API
when 'success' when 'success'
job.success job.success
when 'failed' when 'failed'
job.drop(:job_failure) if params[:failure_reason]
job.drop(params[:failure_reason].to_sym)
else
job.drop(:job_failure)
end
end end
end end
......
...@@ -278,6 +278,7 @@ CommitStatus: ...@@ -278,6 +278,7 @@ CommitStatus:
- auto_canceled_by_id - auto_canceled_by_id
- retried - retried
- protected - protected
- failure_reason
Ci::Variable: Ci::Variable:
- id - id
- project_id - project_id
......
...@@ -445,22 +445,20 @@ describe CommitStatus do ...@@ -445,22 +445,20 @@ describe CommitStatus do
end end
describe 'set failure_reason when drop' do describe 'set failure_reason when drop' do
let(:build) { create(:ci_build, :created) } let(:commit_status) { create(:commit_status, :created) }
before do subject { commit_status.drop!(reason); commit_status }
build.drop!(reason)
end
context 'when failure_reason is nil' do context 'when failure_reason is nil' do
let(:reason) { } let(:reason) { }
it { expect(build).to be_unknown_failure } it { is_expected.to be_unknown_failure }
end end
context 'when failure_reason is job_failure' do context 'when failure_reason is job_failure' do
let(:reason) { :job_failure } let(:reason) { :job_failure }
it { expect(build).to be_job_failure } it { is_expected.to be_job_failure }
end end
end end
end end
...@@ -143,7 +143,7 @@ describe API::CommitStatuses do ...@@ -143,7 +143,7 @@ describe API::CommitStatuses do
expect(json_response['target_url']).to be_nil expect(json_response['target_url']).to be_nil
expect(json_response['description']).to be_nil expect(json_response['description']).to be_nil
if status == 'failed' if status == 'failed'
expect(CommitStatus.find(json_response['id'])).to be_api_failure expect(json_response['failure_reason']).to eq('api_failure')
end end
end end
end end
......
...@@ -636,6 +636,15 @@ describe API::Runner do ...@@ -636,6 +636,15 @@ describe API::Runner do
expect(job.reload.status).to eq 'failed' expect(job.reload.status).to eq 'failed'
expect(job).to be_job_failure expect(job).to be_job_failure
end end
context 'when failure_reason is given' do
it 'mark job as failed' do
update_job(state: 'failed', failure_reason: 'stuck_or_timeout_failure')
expect(job.reload.status).to eq 'failed'
expect(job).to be_stuck_or_timeout_failure
end
end
end end
context 'when tace is given' do context 'when tace is given' do
......
...@@ -22,7 +22,7 @@ describe Ci::RetryBuildService do ...@@ -22,7 +22,7 @@ describe Ci::RetryBuildService do
%i[type lock_version target_url base_tags %i[type lock_version target_url base_tags
commit_id deployments erased_by_id last_deployment project_id commit_id deployments erased_by_id last_deployment project_id
runner_id tag_taggings taggings tags trigger_request_id runner_id tag_taggings taggings tags trigger_request_id
user_id auto_canceled_by_id retried].freeze user_id auto_canceled_by_id retried failure_reason].freeze
shared_examples 'build duplication' do shared_examples 'build duplication' do
let(:stage) do let(:stage) do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment