Commit 49cabc87 authored by Fabio Pitino's avatar Fabio Pitino

Merge branch 'job-api-return-failure-reason' into 'master'

Return job failure reason in API responses

See merge request gitlab-org/gitlab!74888
parents 03699455 7b143a40
......@@ -252,6 +252,7 @@ Example response:
"finished_at": "2016-01-11T10:15:10.506Z",
"duration": 97.0,
"status": "failed",
"failure_reason": "script_failure",
"tag": false,
"web_url": "https://example.com/foo/bar/-/jobs/42",
"user": null
......
......@@ -71,6 +71,7 @@ Example of response
"runner": null,
"stage": "test",
"status": "failed",
"failure_reason": "script_failure",
"tag": false,
"web_url": "https://example.com/foo/bar/-/jobs/7",
"user": {
......@@ -126,6 +127,7 @@ Example of response
"runner": null,
"stage": "test",
"status": "failed",
"failure_reason": "stuck_or_timeout_failure",
"tag": false,
"web_url": "https://example.com/foo/bar/-/jobs/6",
"user": {
......@@ -207,6 +209,7 @@ Example of response
"runner": null,
"stage": "test",
"status": "failed",
"failure_reason": "stuck_or_timeout_failure",
"tag": false,
"web_url": "https://example.com/foo/bar/-/jobs/6",
"user": {
......@@ -271,6 +274,7 @@ Example of response
"runner": null,
"stage": "test",
"status": "failed",
"failure_reason": "script_failure",
"tag": false,
"web_url": "https://example.com/foo/bar/-/jobs/7",
"user": {
......@@ -443,6 +447,7 @@ Example of response
"runner": null,
"stage": "test",
"status": "failed",
"failure_reason": "script_failure",
"tag": false,
"web_url": "https://example.com/foo/bar/-/jobs/8",
"user": {
......
......@@ -13,6 +13,7 @@ module API
expose :user, with: ::API::Entities::User
expose :commit, with: ::API::Entities::Commit
expose :pipeline, with: ::API::Entities::Ci::PipelineBasic
expose :failure_reason, if: -> (job) { job.failed? }
expose :web_url do |job, _options|
Gitlab::Routing.url_helpers.project_job_url(job.project, job)
......
......@@ -428,6 +428,26 @@ RSpec.describe API::Ci::Jobs do
end
end
context 'when job succeeded' do
it 'does not return failure_reason' do
get api("/projects/#{project.id}/jobs/#{job.id}", api_user)
expect(json_response).not_to include('failure_reason')
end
end
context 'when job failed' do
let(:job) do
create(:ci_build, :failed, :tags, pipeline: pipeline)
end
it 'returns failure_reason' do
get api("/projects/#{project.id}/jobs/#{job.id}", api_user)
expect(json_response).to include('failure_reason')
end
end
context 'when trace artifact record exists with no stored file', :skip_before_request do
before do
create(:ci_job_artifact, :unarchived_trace_artifact, job: job, project: job.project)
......
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