Skip to content
Snippets Groups Projects
Commit 4b908782 authored by Drew Blessing's avatar Drew Blessing Committed by Robert Speicher
Browse files

Fix Jenkins build URL with multi-project

parent 06e6cd50
No related branches found
No related tags found
No related merge requests found
v 8.0.5
- "Multi-project" and "Treat unstable builds as passing" parameters for
the Jenkins CI service are now correctly persisted.
- Correct the build URL when "Multi-project" is enabled for the Jenkins CI
service.
 
v 8.0.4
- Fix multi-project setup for Jenkins
Loading
Loading
Loading
Loading
@@ -11,6 +11,7 @@
# active :boolean default(FALSE), not null
# properties :text
#
require 'uri'
 
class JenkinsService < CiService
prop_accessor :project_url
Loading
Loading
@@ -66,12 +67,20 @@ def pass_unstable?
 
def build_page(sha, ref = nil)
if multiproject_enabled? && ref.present?
"#{project_url}_#{ref}/scm/bySHA1/#{sha}"
URI.encode("#{base_project_url}/#{project.name}_#{ref.gsub('/', '_')}/scm/bySHA1/#{sha}").to_s
else
"#{project_url}/scm/bySHA1/#{sha}"
end
end
 
# When multi-project is enabled we need to have a different URL. Rather than
# relying on the user to provide the proper URL depending on multi-project
# we just parse the URL and make sure it's how we want it.
def base_project_url
url = URI.parse(project_url)
URI.join(url, '/job').to_s
end
def commit_status(sha, ref = nil)
parsed_url = URI.parse(build_page(sha, ref))
 
Loading
Loading
Loading
Loading
@@ -39,6 +39,35 @@ Now navigate to GitLab services page and activate Jenkins
Done! Now when you push to GitLab - it will create a build for Jenkins.
And also you will be able to see merge request build status with a link to the Jenkins build.
 
### Multi-project Configuration
The GitLab Hook plugin in Jenkins supports the automatic creation of a project
for each feature branch. After configuration GitLab will trigger feature branch
builds and a corresponding project will be created in Jenkins.
Configure the GitLab Hook plugin in Jenkins. Go to 'Manage Jenkins' and then
'Configure System'. Find the 'GitLab Web Hook' section and configure as shown below.
![Jenkins Multi-project Configuration](jenkins_multiproject_configuration.png)
In the Jenkins service in GitLab, check the 'Multi-project setup enabled?'.
![Jenkins Multi-project Enabled](jenkins_multiproject_enabled.png)
### Mark unstable build as passing
When using some plugins in Jenkins, an unstable build status will result when
tests are not passing. In these cases the unstable status in Jenkins should
register as a failure in GitLab on the merge request page. In other cases you
may not want an unstable status to display as a build failure in GitLab. Control
this behavior using the 'Should unstable builds be treated as passing?' setting
in the Jenkins service in GitLab.
When checked, unstable builds will display as green or passing in GitLab. By
default unstable builds display in GitLab as red or failed.
![Jenkins Unstable Passing](jenkins_unstable_passing.png)
## Development
 
An explanation of how this works in case anyone want to improve it or develop this service for another CI tool.
Loading
Loading
doc/integration/jenkins_gitlab_service.png

34.7 KiB | W: 1185px | H: 510px

doc/integration/jenkins_gitlab_service.png

63 KiB | W: 643px | H: 591px

doc/integration/jenkins_gitlab_service.png
doc/integration/jenkins_gitlab_service.png
doc/integration/jenkins_gitlab_service.png
doc/integration/jenkins_gitlab_service.png
  • 2-up
  • Swipe
  • Onion skin
doc/integration/jenkins_multiproject_configuration.png

24.5 KiB

doc/integration/jenkins_multiproject_enabled.png

63.3 KiB

doc/integration/jenkins_unstable_passing.png

63.3 KiB

Loading
Loading
@@ -40,7 +40,7 @@ def status_body_for_icon(state)
@service = JenkinsService.new
allow(@service).to receive_messages(
service_hook: true,
project_url: 'http://jenkins.gitlab.org/projects/2',
project_url: 'http://jenkins.gitlab.org/job/2',
multiproject_enabled: '0',
pass_unstable: '0',
token: 'verySecret'
Loading
Loading
@@ -50,7 +50,7 @@ def status_body_for_icon(state)
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
stub_request(:get, "http://jenkins.gitlab.org/projects/2/scm/bySHA1/2ab7834c").to_return(status: 200, body: status_body_for_icon(icon), headers: {})
stub_request(:get, "http://jenkins.gitlab.org/job/2/scm/bySHA1/2ab7834c").to_return(status: 200, body: status_body_for_icon(icon), headers: {})
expect(@service.commit_status("2ab7834c", 'master')).to eq(state)
end
end
Loading
Loading
@@ -61,7 +61,7 @@ def status_body_for_icon(state)
@service = JenkinsService.new
allow(@service).to receive_messages(
service_hook: true,
project_url: 'http://jenkins.gitlab.org/projects/2',
project_url: 'http://jenkins.gitlab.org/job/2',
multiproject_enabled: '0',
pass_unstable: '1',
token: 'verySecret'
Loading
Loading
@@ -69,28 +69,30 @@ def status_body_for_icon(state)
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: {})
stub_request(:get, "http://jenkins.gitlab.org/job/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
let!(:project) { create(:project) }
before do
@service = JenkinsService.new
allow(@service).to receive_messages(
service_hook: true,
project_url: 'http://jenkins.gitlab.org/projects/2',
project_url: 'http://jenkins.gitlab.org/job/2',
multiproject_enabled: '1',
token: 'verySecret'
token: 'verySecret',
project: project
)
end
 
describe :build_page do
it { expect(@service.build_page("2ab7834c", 'master')).to eq("http://jenkins.gitlab.org/projects/2_master/scm/bySHA1/2ab7834c") }
it { expect(@service.build_page("2ab7834c", 'master')).to eq("http://jenkins.gitlab.org/job/#{project.name}_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") }
it { expect(@service.build_page("2ab7834c", 'test_branch')).to eq("http://jenkins.gitlab.org/job/#{project.name}_test_branch/scm/bySHA1/2ab7834c") }
end
end
 
Loading
Loading
@@ -99,18 +101,18 @@ def status_body_for_icon(state)
@service = JenkinsService.new
allow(@service).to receive_messages(
service_hook: true,
project_url: 'http://jenkins.gitlab.org/projects/2',
project_url: 'http://jenkins.gitlab.org/job/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") }
it { expect(@service.build_page("2ab7834c", 'master')).to eq("http://jenkins.gitlab.org/job/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/scm/bySHA1/2ab7834c") }
it { expect(@service.build_page("2ab7834c", 'test_branch')).to eq("http://jenkins.gitlab.org/job/2/scm/bySHA1/2ab7834c") }
end
end
end
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment