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
Tatuya Kamada
gitlab-ce
Commits
6b979687
Commit
6b979687
authored
Sep 14, 2016
by
Kamil Trzcinski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update support for dynamic environments
parent
e1b3ab5a
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
49 additions
and
32 deletions
+49
-32
app/models/ci/build.rb
app/models/ci/build.rb
+1
-1
app/services/create_deployment_service.rb
app/services/create_deployment_service.rb
+8
-8
lib/expand_variables.rb
lib/expand_variables.rb
+1
-1
lib/gitlab/ci/config/node/environment.rb
lib/gitlab/ci/config/node/environment.rb
+10
-6
lib/gitlab/ci/config/node/job.rb
lib/gitlab/ci/config/node/job.rb
+1
-9
spec/lib/ci/gitlab_ci_yaml_processor_spec.rb
spec/lib/ci/gitlab_ci_yaml_processor_spec.rb
+14
-0
spec/services/create_deployment_service_spec.rb
spec/services/create_deployment_service_spec.rb
+14
-7
No files found.
app/models/ci/build.rb
View file @
6b979687
...
@@ -86,7 +86,7 @@ module Ci
...
@@ -86,7 +86,7 @@ module Ci
ref:
build
.
ref
,
ref:
build
.
ref
,
tag:
build
.
tag
,
tag:
build
.
tag
,
options:
build
.
options
[
:environment
],
options:
build
.
options
[
:environment
],
variables:
variables
)
variables:
build
.
variables
)
service
.
execute
(
build
)
service
.
execute
(
build
)
end
end
end
end
...
...
app/services/create_deployment_service.rb
View file @
6b979687
...
@@ -2,13 +2,7 @@ require_relative 'base_service'
...
@@ -2,13 +2,7 @@ require_relative 'base_service'
class
CreateDeploymentService
<
BaseService
class
CreateDeploymentService
<
BaseService
def
execute
(
deployable
=
nil
)
def
execute
(
deployable
=
nil
)
environment
=
project
.
environments
.
find_or_create_by
(
environment
=
find_or_create_environment
name:
expanded_name
)
if
expanded_url
environment
.
external_url
=
expanded_url
end
project
.
deployments
.
create
(
project
.
deployments
.
create
(
environment:
environment
,
environment:
environment
,
...
@@ -22,6 +16,12 @@ class CreateDeploymentService < BaseService
...
@@ -22,6 +16,12 @@ class CreateDeploymentService < BaseService
private
private
def
find_or_create_environment
project
.
environments
.
find_or_create_by
(
name:
expanded_name
)
do
|
environment
|
environment
.
external_url
=
expanded_url
end
end
def
expanded_name
def
expanded_name
ExpandVariables
.
expand
(
name
,
variables
)
ExpandVariables
.
expand
(
name
,
variables
)
end
end
...
@@ -41,7 +41,7 @@ class CreateDeploymentService < BaseService
...
@@ -41,7 +41,7 @@ class CreateDeploymentService < BaseService
end
end
def
options
def
options
params
[
:
environment
]
||
{}
params
[
:
options
]
||
{}
end
end
def
variables
def
variables
...
...
lib/expand_variables.rb
View file @
6b979687
module
ExpandVariables
module
ExpandVariables
class
<<
self
class
<<
self
def
expand
_variables
(
value
,
variables
)
def
expand
(
value
,
variables
)
# Convert hash array to variables
# Convert hash array to variables
if
variables
.
is_a?
(
Array
)
if
variables
.
is_a?
(
Array
)
variables
=
variables
.
reduce
({})
do
|
hash
,
variable
|
variables
=
variables
.
reduce
({})
do
|
hash
,
variable
|
...
...
lib/gitlab/ci/config/node/environment.rb
View file @
6b979687
...
@@ -8,7 +8,11 @@ module Gitlab
...
@@ -8,7 +8,11 @@ module Gitlab
class
Environment
<
Entry
class
Environment
<
Entry
include
Validatable
include
Validatable
ALLOWED_KEYS
=
%i[name url]
validations
do
validations
do
validates
:config
,
allowed_keys:
ALLOWED_KEYS
,
if: :hash?
validates
:name
,
presence:
true
validates
:name
,
presence:
true
validates
:url
,
validates
:url
,
...
@@ -32,9 +36,9 @@ module Gitlab
...
@@ -32,9 +36,9 @@ module Gitlab
end
end
def
name
def
name
case
case
@config
.
type
when
string?
then
@config
when
String
then
@config
when
hash
?
then
@config
[:
name
]
when
Hash
then
@config
[
:name
]
end
end
end
end
...
@@ -43,9 +47,9 @@ module Gitlab
...
@@ -43,9 +47,9 @@ module Gitlab
end
end
def
value
def
value
case
case
@config
.
type
when
string?
then
{
name:
@config
}
when
String
then
{
name:
@config
}
when
hash
?
then
@config
when
Hash
then
@config
end
end
end
end
end
end
...
...
lib/gitlab/ci/config/node/job.rb
View file @
6b979687
...
@@ -29,14 +29,6 @@ module Gitlab
...
@@ -29,14 +29,6 @@ module Gitlab
inclusion:
{
in:
%w[on_success on_failure always manual]
,
inclusion:
{
in:
%w[on_success on_failure always manual]
,
message:
'should be on_success, on_failure, '
\
message:
'should be on_success, on_failure, '
\
'always or manual'
}
'always or manual'
}
validates
:environment
,
type:
{
with:
String
,
message:
Gitlab
::
Regex
.
environment_name_regex_message
}
validates
:environment
,
format:
{
with:
Gitlab
::
Regex
.
environment_name_regex
,
message:
Gitlab
::
Regex
.
environment_name_regex_message
}
validates
:dependencies
,
array_of_strings:
true
validates
:dependencies
,
array_of_strings:
true
end
end
...
@@ -83,7 +75,7 @@ module Gitlab
...
@@ -83,7 +75,7 @@ module Gitlab
helpers
:before_script
,
:script
,
:stage
,
:type
,
:after_script
,
helpers
:before_script
,
:script
,
:stage
,
:type
,
:after_script
,
:cache
,
:image
,
:services
,
:only
,
:except
,
:variables
,
:cache
,
:image
,
:services
,
:only
,
:except
,
:variables
,
:artifacts
,
:commands
:artifacts
,
:commands
,
:environment
def
compose!
(
deps
=
nil
)
def
compose!
(
deps
=
nil
)
super
do
super
do
...
...
spec/lib/ci/gitlab_ci_yaml_processor_spec.rb
View file @
6b979687
...
@@ -754,6 +754,20 @@ module Ci
...
@@ -754,6 +754,20 @@ module Ci
it
'does return production'
do
it
'does return production'
do
expect
(
builds
.
size
).
to
eq
(
1
)
expect
(
builds
.
size
).
to
eq
(
1
)
expect
(
builds
.
first
[
:environment
]).
to
eq
(
environment
)
expect
(
builds
.
first
[
:environment
]).
to
eq
(
environment
)
expect
(
builds
.
first
[
:options
]).
to
include
(
environment:
{
name:
environment
})
end
end
context
'when hash is specified'
do
let
(
:environment
)
do
{
name:
'production'
,
url:
'http://production.gitlab.com'
}
end
it
'does return production and URL'
do
expect
(
builds
.
size
).
to
eq
(
1
)
expect
(
builds
.
first
[
:environment
]).
to
eq
(
environment
[
:name
])
expect
(
builds
.
first
[
:options
]).
to
include
(
environment
)
end
end
end
end
...
...
spec/services/create_deployment_service_spec.rb
View file @
6b979687
...
@@ -41,7 +41,7 @@ describe CreateDeploymentService, services: true do
...
@@ -41,7 +41,7 @@ describe CreateDeploymentService, services: true do
context
'for environment with invalid name'
do
context
'for environment with invalid name'
do
let
(
:params
)
do
let
(
:params
)
do
{
environment:
'
name with spaces
'
,
{
environment:
'
..
'
,
ref:
'master'
,
ref:
'master'
,
tag:
false
,
tag:
false
,
sha:
'97de212e80737a608d939f648d959671fb0a0142'
,
sha:
'97de212e80737a608d939f648d959671fb0a0142'
,
...
@@ -64,10 +64,8 @@ describe CreateDeploymentService, services: true do
...
@@ -64,10 +64,8 @@ describe CreateDeploymentService, services: true do
tag:
false
,
tag:
false
,
sha:
'97de212e80737a608d939f648d959671fb0a0142'
,
sha:
'97de212e80737a608d939f648d959671fb0a0142'
,
options:
{
options:
{
environment:
{
name:
'review-apps/$CI_BUILD_REF_NAME'
,
name:
'review-apps/$CI_BUILD_REF_NAME'
,
url:
'http://$CI_BUILD_REF_NAME.review-apps.gitlab.com'
url:
'http://$CI_BUILD_REF_NAME.review-apps.gitlab.com'
}
},
},
variables:
[
variables:
[
{
key:
'CI_BUILD_REF_NAME'
,
value:
'feature-review-apps'
}
{
key:
'CI_BUILD_REF_NAME'
,
value:
'feature-review-apps'
}
...
@@ -83,7 +81,7 @@ describe CreateDeploymentService, services: true do
...
@@ -83,7 +81,7 @@ describe CreateDeploymentService, services: true do
end
end
it
'does create a new deployment'
do
it
'does create a new deployment'
do
expect
(
subject
).
not_
to
be_persisted
expect
(
subject
).
to
be_persisted
end
end
end
end
end
end
...
@@ -125,6 +123,12 @@ describe CreateDeploymentService, services: true do
...
@@ -125,6 +123,12 @@ describe CreateDeploymentService, services: true do
expect
(
Deployment
.
last
.
deployable
).
to
eq
(
deployable
)
expect
(
Deployment
.
last
.
deployable
).
to
eq
(
deployable
)
end
end
it
'create environment has URL set'
do
subject
expect
(
Deployment
.
last
.
environment
.
external_url
).
not_to
be_nil
end
end
end
context
'without environment specified'
do
context
'without environment specified'
do
...
@@ -137,7 +141,10 @@ describe CreateDeploymentService, services: true do
...
@@ -137,7 +141,10 @@ describe CreateDeploymentService, services: true do
context
'when environment is specified'
do
context
'when environment is specified'
do
let
(
:pipeline
)
{
create
(
:ci_pipeline
,
project:
project
)
}
let
(
:pipeline
)
{
create
(
:ci_pipeline
,
project:
project
)
}
let
(
:build
)
{
create
(
:ci_build
,
pipeline:
pipeline
,
environment:
'production'
)
}
let
(
:build
)
{
create
(
:ci_build
,
pipeline:
pipeline
,
environment:
'production'
,
options:
options
)
}
let
(
:options
)
do
{
environment:
{
name:
'production'
,
url:
'http://gitlab.com'
}
}
end
context
'when build succeeds'
do
context
'when build succeeds'
do
it_behaves_like
'does create environment and deployment'
do
it_behaves_like
'does create environment and deployment'
do
...
...
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