Commit 55b8dd83 authored by Marius Bobin's avatar Marius Bobin

Set failed commit status when TeamCity is unreachable

parent ea4e4edb
......@@ -87,6 +87,11 @@ class TeamcityService < CiService
response = get_path("httpAuth/app/rest/builds/branch:unspecified:any,revision:#{sha}")
{ build_page: read_build_page(response), commit_status: read_commit_status(response) }
rescue Errno::ECONNREFUSED => e
Gitlab::ErrorTracking.log_exception(e, project_id: project_id)
{ build_page: teamcity_url, commit_status: :error }
end
def execute(data)
......
---
title: Set commit status to failed if the TeamCity connection is refused
merge_request: 27395
author:
type: fixed
......@@ -7,6 +7,7 @@ describe TeamcityService, :use_clean_rails_memory_store_caching do
include StubRequests
let(:teamcity_url) { 'http://gitlab.com/teamcity' }
let(:teamcity_full_url) { 'http://gitlab.com/teamcity/httpAuth/app/rest/builds/branch:unspecified:any,revision:123' }
let(:project) { create(:project) }
subject(:service) do
......@@ -165,6 +166,16 @@ describe TeamcityService, :use_clean_rails_memory_store_caching do
is_expected.to eq('http://gitlab.com/teamcity/viewLog.html?buildId=666&buildTypeId=foo')
end
end
it 'returns the teamcity_url when teamcity is unreachable' do
stub_full_request(teamcity_full_url).to_raise(Errno::ECONNREFUSED)
expect(Gitlab::ErrorTracking)
.to receive(:log_exception)
.with(instance_of(Errno::ECONNREFUSED), project_id: project.id)
is_expected.to eq(teamcity_url)
end
end
context 'commit_status' do
......@@ -205,6 +216,16 @@ describe TeamcityService, :use_clean_rails_memory_store_caching do
is_expected.to eq(:error)
end
it 'sets commit status to :error when teamcity is unreachable' do
stub_full_request(teamcity_full_url).to_raise(Errno::ECONNREFUSED)
expect(Gitlab::ErrorTracking)
.to receive(:log_exception)
.with(instance_of(Errno::ECONNREFUSED), project_id: project.id)
is_expected.to eq(:error)
end
end
end
......@@ -300,7 +321,6 @@ describe TeamcityService, :use_clean_rails_memory_store_caching do
end
def stub_request(status: 200, body: nil, build_status: 'success')
teamcity_full_url = 'http://gitlab.com/teamcity/httpAuth/app/rest/builds/branch:unspecified:any,revision:123'
auth = %w(mic password)
body ||= %Q({"build":{"status":"#{build_status}","id":"666"}})
......
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