Commit 086bf47e authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge branch 'master' into 'master'

Addresses regression with jenkins setup that does not use the multiproject setup

The Jenkins Gitlab Hook Plugin allows for two kinds of setups.  One where a Jenkins job is created for each branch and one where all branches are built in a single Jenkins job.  MR !9 added support for the multi-job setup but broke the single job setup.  This request addresses #30 and fixes the regression.

See merge request !27
parents 54878022 f80ca51b
......@@ -14,6 +14,8 @@
class JenkinsService < CiService
prop_accessor :project_url
prop_accessor :multiproject_enabled
prop_accessor :pass_unstable
validates :project_url, presence: true, if: :activated?
......@@ -46,13 +48,28 @@ class JenkinsService < CiService
def fields
[
{ type: 'text', name: 'project_url', placeholder: 'Jenkins project URL like http://jenkins.example.com/job/my-project/' }
{ type: 'text', name: 'project_url', placeholder: 'Jenkins project URL like http://jenkins.example.com/job/my-project/' },
{ type: 'checkbox', name: 'multiproject_enabled', title: "Multi-project setup enabled?",
help: "Multi-project mode is configured in Jenkins Gitlab Hook plugin." },
{ type: 'checkbox', name: 'pass_unstable', title: 'Should unstable builds be treated as passing?',
help: 'Unstable builds will be treated as passing.'}
]
end
def multiproject_enabled?
self.multiproject_enabled == '1'
end
def pass_unstable?
self.pass_unstable == '1'
end
def build_page(sha, ref = nil)
base_url = ref.nil? || ref == 'master' ? project_url : "#{project_url}_#{ref}"
base_url + "/scm/bySHA1/#{sha}"
if multiproject_enabled? && ref.present?
"#{project_url}_#{ref}/scm/bySHA1/#{sha}"
else
"#{project_url}/scm/bySHA1/#{sha}"
end
end
def commit_status(sha, ref = nil)
......@@ -72,7 +89,7 @@ class JenkinsService < CiService
if response.code == 200
# img.build-caption-status-icon for old jenkins version
src = Nokogiri.parse(response).css('img.build-caption-status-icon,.build-caption>img').first.attributes['src'].value
if src =~ /blue\.png$/
if src =~ /blue\.png$/ || (src =~ /yellow\.png/ && pass_unstable?)
'success'
elsif src =~ /(red|aborted|yellow)\.png$/
'failed'
......
......@@ -35,16 +35,18 @@ describe JenkinsService do
eos
end
describe :commit_status do
before do
@service = JenkinsService.new
allow(@service).to receive_messages(
service_hook: true,
project_url: 'http://jenkins.gitlab.org/projects/2',
multiproject_enabled: '0',
pass_unstable: '0',
token: 'verySecret'
)
end
describe :commit_status do
statuses = { 'blue.png' => 'success', 'yellow.png' => 'failed', 'red.png' => 'failed', 'aborted.png' => 'failed', 'blue-anime.gif' => 'running', 'grey.png' => 'pending' }
statuses.each do |icon, state|
it "should have a status of #{state} when the icon #{icon} exists." do
......@@ -54,12 +56,62 @@ eos
end
end
describe 'commit status with passing unstable' do
before do
@service = JenkinsService.new
allow(@service).to receive_messages(
service_hook: true,
project_url: 'http://jenkins.gitlab.org/projects/2',
multiproject_enabled: '0',
pass_unstable: '1',
token: 'verySecret'
)
end
it "should have a status of success when the icon yellow exists." do
stub_request(:get, "http://jenkins.gitlab.org/projects/2/scm/bySHA1/2ab7834c").to_return(status: 200, body: status_body_for_icon('yellow.png'), headers: {})
expect(@service.commit_status("2ab7834c", 'master')).to eq('success')
end
end
describe 'multiproject enabled' do
before do
@service = JenkinsService.new
allow(@service).to receive_messages(
service_hook: true,
project_url: 'http://jenkins.gitlab.org/projects/2',
multiproject_enabled: '1',
token: 'verySecret'
)
end
describe :build_page do
it { expect(@service.build_page("2ab7834c", 'master')).to eq("http://jenkins.gitlab.org/projects/2_master/scm/bySHA1/2ab7834c") }
end
describe :build_page_with_branch do
it { expect(@service.build_page("2ab7834c", 'test_branch')).to eq("http://jenkins.gitlab.org/projects/2_test_branch/scm/bySHA1/2ab7834c") }
end
end
describe 'multiproject disabled' do
before do
@service = JenkinsService.new
allow(@service).to receive_messages(
service_hook: true,
project_url: 'http://jenkins.gitlab.org/projects/2',
multiproject_enabled: '0',
token: 'verySecret'
)
end
describe :build_page do
it { expect(@service.build_page("2ab7834c", 'master')).to eq("http://jenkins.gitlab.org/projects/2/scm/bySHA1/2ab7834c") }
end
describe :build_page_with_branch do
it { expect(@service.build_page("2ab7834c", 'test_branch')).to eq("http://jenkins.gitlab.org/projects/2_test_branch/scm/bySHA1/2ab7834c") }
it { expect(@service.build_page("2ab7834c", 'test_branch')).to eq("http://jenkins.gitlab.org/projects/2/scm/bySHA1/2ab7834c") }
end
end
end
end
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