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
0
Merge Requests
0
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
Jérome Perrin
gitlab-ce
Commits
6209b60c
Commit
6209b60c
authored
Jun 14, 2016
by
Kamil Trzcinski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Properly create a new deployment after build success
parent
bb6f2467
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
68 additions
and
6 deletions
+68
-6
app/models/ci/build.rb
app/models/ci/build.rb
+6
-2
spec/services/create_deployment_service_spec.rb
spec/services/create_deployment_service_spec.rb
+62
-4
No files found.
app/models/ci/build.rb
View file @
6209b60c
...
@@ -75,9 +75,13 @@ module Ci
...
@@ -75,9 +75,13 @@ module Ci
build
.
execute_hooks
build
.
execute_hooks
end
end
after_transition
any
: :success
do
|
build
|
after_transition
any
=>
[
:success
]
do
|
build
|
if
build
.
environment
.
present?
if
build
.
environment
.
present?
CreateDeploymentService
.
new
(
build
.
project
,
build
.
user
,
environment:
build
.
environment
).
execute
(
build
)
service
=
CreateDeploymentService
.
new
(
build
.
project
,
build
.
user
,
environment:
build
.
environment
,
sha:
build
.
sha
,
ref:
build
.
ref
,
tag:
build
.
tag
)
service
.
execute
(
build
)
end
end
end
end
end
end
...
...
spec/services/create_deployment_service_spec.rb
View file @
6209b60c
require
'spec_helper'
require
'spec_helper'
describe
CreateDeploymentService
,
services:
true
do
describe
CreateDeploymentService
,
services:
true
do
let
(
:build
)
{
create
(
:ci_build
)
}
let
(
:project
)
{
create
(
:empty_project
)
}
let
(
:project
)
{
build
.
project
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:service
)
{
described_class
.
new
(
project
,
user
,
params
)
}
let
(
:service
)
{
described_class
.
new
(
project
,
user
,
params
)
}
...
@@ -11,7 +10,7 @@ describe CreateDeploymentService, services: true do
...
@@ -11,7 +10,7 @@ describe CreateDeploymentService, services: true do
let
(
:params
)
do
let
(
:params
)
do
{
environment:
'production'
,
{
environment:
'production'
,
ref:
'master'
,
ref:
'master'
,
sha:
build
.
sha
,
sha:
'97de212e80737a608d939f648d959671fb0a0142'
,
}
}
end
end
...
@@ -43,7 +42,7 @@ describe CreateDeploymentService, services: true do
...
@@ -43,7 +42,7 @@ describe CreateDeploymentService, services: true do
let
(
:params
)
do
let
(
:params
)
do
{
environment:
'name with spaces'
,
{
environment:
'name with spaces'
,
ref:
'master'
,
ref:
'master'
,
sha:
build
.
sha
,
sha:
'97de212e80737a608d939f648d959671fb0a0142'
,
}
}
end
end
...
@@ -56,4 +55,63 @@ describe CreateDeploymentService, services: true do
...
@@ -56,4 +55,63 @@ describe CreateDeploymentService, services: true do
end
end
end
end
end
end
describe
'processing of builds'
do
let
(
:environment
)
{
nil
}
shared_examples
'does not create environment and deployment'
do
it
'does not create a new environment'
do
expect
{
subject
}.
not_to
change
{
Environment
.
count
}
end
it
'does not create a new deployment'
do
expect
{
subject
}.
not_to
change
{
Deployment
.
count
}
end
it
'does not call a service'
do
expect_any_instance_of
(
described_class
).
not_to
receive
(
:execute
)
subject
end
end
shared_examples
'does create environment and deployment'
do
it
'does create a new environment'
do
expect
{
subject
}.
to
change
{
Environment
.
count
}.
by
(
1
)
end
it
'does create a new deployment'
do
expect
{
subject
}.
to
change
{
Deployment
.
count
}.
by
(
1
)
end
it
'does call a service'
do
expect_any_instance_of
(
described_class
).
to
receive
(
:execute
)
subject
end
end
context
'without environment specified'
do
let
(
:build
)
{
create
(
:ci_build
,
project:
project
)
}
it_behaves_like
'does not create environment and deployment'
do
subject
{
build
.
success
}
end
end
context
'when environment is specified'
do
let
(
:pipeline
)
{
create
(
:ci_pipeline
,
project:
project
)
}
let
(
:build
)
{
create
(
:ci_build
,
pipeline:
pipeline
,
environment:
'production'
)
}
context
'when build succeeds'
do
it_behaves_like
'does create environment and deployment'
do
subject
{
build
.
success
}
end
end
context
'when build fails'
do
it_behaves_like
'does not create environment and deployment'
do
subject
{
build
.
drop
}
end
end
end
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