Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
f36b0c99
Commit
f36b0c99
authored
Oct 08, 2015
by
Drew Blessing
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix Jenkins build URL with multi-project
parent
086bf47e
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
53 additions
and
13 deletions
+53
-13
app/models/project_services/jenkins_service.rb
app/models/project_services/jenkins_service.rb
+11
-2
doc/integration/jenkins.md
doc/integration/jenkins.md
+29
-0
doc/integration/jenkins_gitlab_service.png
doc/integration/jenkins_gitlab_service.png
+0
-0
doc/integration/jenkins_multiproject_configuration.png
doc/integration/jenkins_multiproject_configuration.png
+0
-0
doc/integration/jenkins_multiproject_enabled.png
doc/integration/jenkins_multiproject_enabled.png
+0
-0
doc/integration/jenkins_unstable_passing.png
doc/integration/jenkins_unstable_passing.png
+0
-0
spec/models/project_services/jenkins_service_spec.rb
spec/models/project_services/jenkins_service_spec.rb
+13
-11
No files found.
app/models/project_services/jenkins_service.rb
View file @
f36b0c99
...
...
@@ -11,6 +11,7 @@
# active :boolean default(FALSE), not null
# properties :text
#
require
'uri'
class
JenkinsService
<
CiService
prop_accessor
:project_url
...
...
@@ -52,7 +53,7 @@ class JenkinsService < CiService
{
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.'
}
help:
'Unstable builds will be treated as passing.'
}
]
end
...
...
@@ -66,12 +67,20 @@ class JenkinsService < CiService
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
))
...
...
doc/integration/jenkins.md
View file @
f36b0c99
...
...
@@ -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.
...
...
doc/integration/jenkins_gitlab_service.png
View replaced file @
086bf47e
View file @
f36b0c99
34.7 KB
|
W:
|
H:
63 KB
|
W:
|
H:
2-up
Swipe
Onion skin
doc/integration/jenkins_multiproject_configuration.png
0 → 100644
View file @
f36b0c99
24.5 KB
doc/integration/jenkins_multiproject_enabled.png
0 → 100644
View file @
f36b0c99
63.3 KB
doc/integration/jenkins_unstable_passing.png
0 → 100644
View file @
f36b0c99
63.3 KB
spec/models/project_services/jenkins_service_spec.rb
View file @
f36b0c99
...
...
@@ -40,7 +40,7 @@ eos
@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'
...
...
@@ -50,7 +50,7 @@ eos
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
...
...
@@ -61,7 +61,7 @@ eos
@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'
...
...
@@ -69,28 +69,30 @@ eos
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
...
...
@@ -99,18 +101,18 @@ eos
@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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment