Commit 0db9458f authored by Kamil Trzciński's avatar Kamil Trzciński

Merge branch '51273-expose-runners-for-build-in-job-api' into 'master'

Expose runners status information in job api

Closes #51273

See merge request gitlab-org/gitlab-ce!21618
parents 953018e3 67376431
...@@ -123,11 +123,6 @@ module CiStatusHelper ...@@ -123,11 +123,6 @@ module CiStatusHelper
render_status_with_link('pipeline', pipeline.status, path, tooltip_placement: tooltip_placement) render_status_with_link('pipeline', pipeline.status, path, tooltip_placement: tooltip_placement)
end end
def no_runners_for_project?(project)
project.runners.blank? &&
Ci::Runner.instance_type.blank?
end
def render_status_with_link(type, status, path = nil, tooltip_placement: 'left', cssclass: '', container: 'body', icon_size: 16) def render_status_with_link(type, status, path = nil, tooltip_placement: 'left', cssclass: '', container: 'body', icon_size: 16)
klass = "ci-status-link ci-status-icon-#{status.dasherize} #{cssclass}" klass = "ci-status-link ci-status-icon-#{status.dasherize} #{cssclass}"
title = "#{type.titleize}: #{ci_label_for_status(status)}" title = "#{type.titleize}: #{ci_label_for_status(status)}"
......
...@@ -79,6 +79,20 @@ class BuildDetailsEntity < JobEntity ...@@ -79,6 +79,20 @@ class BuildDetailsEntity < JobEntity
expose :trigger_variables, as: :variables, using: TriggerVariableEntity expose :trigger_variables, as: :variables, using: TriggerVariableEntity
end end
expose :runners do
expose :online do |build|
build.any_runners_online?
end
expose :available do |build|
project.any_runners?
end
expose :settings_path, if: -> (*) { can_admin_build? } do |build|
project_runners_path(project)
end
end
private private
def build_failed_issue_options def build_failed_issue_options
...@@ -97,4 +111,8 @@ class BuildDetailsEntity < JobEntity ...@@ -97,4 +111,8 @@ class BuildDetailsEntity < JobEntity
def can_create_build_terminal? def can_create_build_terminal?
can?(current_user, :create_build_terminal, build) && build.has_terminal? can?(current_user, :create_build_terminal, build) && build.has_terminal?
end end
def can_admin_build?
can?(request.current_user, :admin_build, project)
end
end end
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
- unless @build.any_runners_online? - unless @build.any_runners_online?
.bs-callout.bs-callout-warning.js-build-stuck .bs-callout.bs-callout-warning.js-build-stuck
%p %p
- if no_runners_for_project?(@build.project) - if @project.any_runners?
This job is stuck, because the project doesn't have any runners online assigned to it. This job is stuck, because the project doesn't have any runners online assigned to it.
- elsif @build.tags.any? - elsif @build.tags.any?
This job is stuck, because you don't have any active runners online with any of these tags assigned to them: This job is stuck, because you don't have any active runners online with any of these tags assigned to them:
......
---
title: Expose project runners in job API
merge_request: 21618
author:
type: other
...@@ -288,6 +288,55 @@ describe Projects::JobsController, :clean_gitlab_redis_shared_state do ...@@ -288,6 +288,55 @@ describe Projects::JobsController, :clean_gitlab_redis_shared_state do
end end
end end
end end
context 'when no runners are available' do
let(:runner) { create(:ci_runner, :instance, active: false) }
let(:job) { create(:ci_build, :pending, pipeline: pipeline, runner: runner) }
it 'exposes needed information' do
expect(response).to have_gitlab_http_status(:ok)
expect(response).to match_response_schema('job/job_details')
expect(json_response['runners']['online']).to be false
expect(json_response['runners']['available']).to be false
end
end
context 'when no runner is online' do
let(:runner) { create(:ci_runner, :instance) }
let(:job) { create(:ci_build, :pending, pipeline: pipeline, runner: runner) }
it 'exposes needed information' do
expect(response).to have_gitlab_http_status(:ok)
expect(response).to match_response_schema('job/job_details')
expect(json_response['runners']['online']).to be false
expect(json_response['runners']['available']).to be true
end
end
context 'settings_path' do
context 'when user is developer' do
it 'settings_path is not available' do
expect(response).to have_gitlab_http_status(:ok)
expect(response).to match_response_schema('job/job_details')
expect(json_response['runners']).not_to have_key('settings_path')
end
end
context 'when user is maintainer' do
let(:user) { create(:user, :admin) }
before do
project.add_maintainer(user)
sign_in(user)
end
it 'settings_path is available' do
expect(response).to have_gitlab_http_status(:ok)
expect(response).to match_response_schema('job/job_details')
expect(json_response['runners']['settings_path']).to match(/runners/)
end
end
end
end end
context 'when requesting JSON job is triggered' do context 'when requesting JSON job is triggered' do
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
"terminal_path": { "type": "string" }, "terminal_path": { "type": "string" },
"trigger": { "$ref": "trigger.json" }, "trigger": { "$ref": "trigger.json" },
"deployment_status": { "$ref": "deployment_status.json" }, "deployment_status": { "$ref": "deployment_status.json" },
"runner": { "$ref": "runner.json" } "runner": { "$ref": "runner.json" },
"runners": { "type": "runners.json" }
} }
} }
{
"type": "object",
"required": [
"online",
"available"
],
"properties": {
"online": { "type": "boolean" },
"available": { "type": "boolean" },
"settings_path": { "type": "string" }
},
"additionalProperties": false
}
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