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: ...@@ -252,6 +252,7 @@ Example response:
"finished_at": "2016-01-11T10:15:10.506Z", "finished_at": "2016-01-11T10:15:10.506Z",
"duration": 97.0, "duration": 97.0,
"status": "failed", "status": "failed",
"failure_reason": "script_failure",
"tag": false, "tag": false,
"web_url": "https://example.com/foo/bar/-/jobs/42", "web_url": "https://example.com/foo/bar/-/jobs/42",
"user": null "user": null
......
...@@ -71,6 +71,7 @@ Example of response ...@@ -71,6 +71,7 @@ Example of response
"runner": null, "runner": null,
"stage": "test", "stage": "test",
"status": "failed", "status": "failed",
"failure_reason": "script_failure",
"tag": false, "tag": false,
"web_url": "https://example.com/foo/bar/-/jobs/7", "web_url": "https://example.com/foo/bar/-/jobs/7",
"user": { "user": {
...@@ -126,6 +127,7 @@ Example of response ...@@ -126,6 +127,7 @@ Example of response
"runner": null, "runner": null,
"stage": "test", "stage": "test",
"status": "failed", "status": "failed",
"failure_reason": "stuck_or_timeout_failure",
"tag": false, "tag": false,
"web_url": "https://example.com/foo/bar/-/jobs/6", "web_url": "https://example.com/foo/bar/-/jobs/6",
"user": { "user": {
...@@ -207,6 +209,7 @@ Example of response ...@@ -207,6 +209,7 @@ Example of response
"runner": null, "runner": null,
"stage": "test", "stage": "test",
"status": "failed", "status": "failed",
"failure_reason": "stuck_or_timeout_failure",
"tag": false, "tag": false,
"web_url": "https://example.com/foo/bar/-/jobs/6", "web_url": "https://example.com/foo/bar/-/jobs/6",
"user": { "user": {
...@@ -271,6 +274,7 @@ Example of response ...@@ -271,6 +274,7 @@ Example of response
"runner": null, "runner": null,
"stage": "test", "stage": "test",
"status": "failed", "status": "failed",
"failure_reason": "script_failure",
"tag": false, "tag": false,
"web_url": "https://example.com/foo/bar/-/jobs/7", "web_url": "https://example.com/foo/bar/-/jobs/7",
"user": { "user": {
...@@ -443,6 +447,7 @@ Example of response ...@@ -443,6 +447,7 @@ Example of response
"runner": null, "runner": null,
"stage": "test", "stage": "test",
"status": "failed", "status": "failed",
"failure_reason": "script_failure",
"tag": false, "tag": false,
"web_url": "https://example.com/foo/bar/-/jobs/8", "web_url": "https://example.com/foo/bar/-/jobs/8",
"user": { "user": {
......
...@@ -13,6 +13,7 @@ module API ...@@ -13,6 +13,7 @@ module API
expose :user, with: ::API::Entities::User expose :user, with: ::API::Entities::User
expose :commit, with: ::API::Entities::Commit expose :commit, with: ::API::Entities::Commit
expose :pipeline, with: ::API::Entities::Ci::PipelineBasic expose :pipeline, with: ::API::Entities::Ci::PipelineBasic
expose :failure_reason, if: -> (job) { job.failed? }
expose :web_url do |job, _options| expose :web_url do |job, _options|
Gitlab::Routing.url_helpers.project_job_url(job.project, job) Gitlab::Routing.url_helpers.project_job_url(job.project, job)
......
...@@ -428,6 +428,26 @@ RSpec.describe API::Ci::Jobs do ...@@ -428,6 +428,26 @@ RSpec.describe API::Ci::Jobs do
end end
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 context 'when trace artifact record exists with no stored file', :skip_before_request do
before do before do
create(:ci_job_artifact, :unarchived_trace_artifact, job: job, project: job.project) 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