BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
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
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
47 additions
and
30 deletions
+47
-30
build.rb
app/models/ci/build.rb
+1
-1
create_deployment_service.rb
app/services/create_deployment_service.rb
+8
-8
expand_variables.rb
lib/expand_variables.rb
+1
-1
environment.rb
lib/gitlab/ci/config/node/environment.rb
+10
-6
job.rb
lib/gitlab/ci/config/node/job.rb
+1
-9
gitlab_ci_yaml_processor_spec.rb
spec/lib/ci/gitlab_ci_yaml_processor_spec.rb
+14
-0
create_deployment_service_spec.rb
spec/services/create_deployment_service_spec.rb
+12
-5
No files found.
app/models/ci/build.rb
View file @
6b979687
...
...
@@ -86,7 +86,7 @@ module Ci
ref:
build
.
ref
,
tag:
build
.
tag
,
options:
build
.
options
[
:environment
],
variables:
variables
)
variables:
build
.
variables
)
service
.
execute
(
build
)
end
end
...
...
app/services/create_deployment_service.rb
View file @
6b979687
...
...
@@ -2,13 +2,7 @@ require_relative 'base_service'
class
CreateDeploymentService
<
BaseService
def
execute
(
deployable
=
nil
)
environment
=
project
.
environments
.
find_or_create_by
(
name:
expanded_name
)
if
expanded_url
environment
.
external_url
=
expanded_url
end
environment
=
find_or_create_environment
project
.
deployments
.
create
(
environment:
environment
,
...
...
@@ -22,6 +16,12 @@ class CreateDeploymentService < BaseService
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
ExpandVariables
.
expand
(
name
,
variables
)
end
...
...
@@ -41,7 +41,7 @@ class CreateDeploymentService < BaseService
end
def
options
params
[
:
environment
]
||
{}
params
[
:
options
]
||
{}
end
def
variables
...
...
lib/expand_variables.rb
View file @
6b979687
module
ExpandVariables
class
<<
self
def
expand
_variables
(
value
,
variables
)
def
expand
(
value
,
variables
)
# Convert hash array to variables
if
variables
.
is_a?
(
Array
)
variables
=
variables
.
reduce
({})
do
|
hash
,
variable
|
...
...
lib/gitlab/ci/config/node/environment.rb
View file @
6b979687
...
...
@@ -8,7 +8,11 @@ module Gitlab
class
Environment
<
Entry
include
Validatable
ALLOWED_KEYS
=
%i[name url]
validations
do
validates
:config
,
allowed_keys:
ALLOWED_KEYS
,
if: :hash?
validates
:name
,
presence:
true
validates
:url
,
...
...
@@ -32,9 +36,9 @@ module Gitlab
end
def
name
case
when
string?
then
@config
when
hash
?
then
@config
[:
name
]
case
@config
.
type
when
String
then
@config
when
Hash
then
@config
[
:name
]
end
end
...
...
@@ -43,9 +47,9 @@ module Gitlab
end
def
value
case
when
string?
then
{
name:
@config
}
when
hash
?
then
@config
case
@config
.
type
when
String
then
{
name:
@config
}
when
Hash
then
@config
end
end
end
...
...
lib/gitlab/ci/config/node/job.rb
View file @
6b979687
...
...
@@ -29,14 +29,6 @@ module Gitlab
inclusion:
{
in:
%w[on_success on_failure always manual]
,
message:
'should be on_success, on_failure, '
\
'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
end
...
...
@@ -83,7 +75,7 @@ module Gitlab
helpers
:before_script
,
:script
,
:stage
,
:type
,
:after_script
,
:cache
,
:image
,
:services
,
:only
,
:except
,
:variables
,
:artifacts
,
:commands
:artifacts
,
:commands
,
:environment
def
compose!
(
deps
=
nil
)
super
do
...
...
spec/lib/ci/gitlab_ci_yaml_processor_spec.rb
View file @
6b979687
...
...
@@ -754,6 +754,20 @@ module Ci
it
'does return production'
do
expect
(
builds
.
size
).
to
eq
(
1
)
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
...
...
spec/services/create_deployment_service_spec.rb
View file @
6b979687
...
...
@@ -41,7 +41,7 @@ describe CreateDeploymentService, services: true do
context
'for environment with invalid name'
do
let
(
:params
)
do
{
environment:
'
name with spaces
'
,
{
environment:
'
..
'
,
ref:
'master'
,
tag:
false
,
sha:
'97de212e80737a608d939f648d959671fb0a0142'
,
...
...
@@ -64,10 +64,8 @@ describe CreateDeploymentService, services: true do
tag:
false
,
sha:
'97de212e80737a608d939f648d959671fb0a0142'
,
options:
{
environment:
{
name:
'review-apps/$CI_BUILD_REF_NAME'
,
url:
'http://$CI_BUILD_REF_NAME.review-apps.gitlab.com'
}
},
variables:
[
{
key:
'CI_BUILD_REF_NAME'
,
value:
'feature-review-apps'
}
...
...
@@ -83,7 +81,7 @@ describe CreateDeploymentService, services: true do
end
it
'does create a new deployment'
do
expect
(
subject
).
not_
to
be_persisted
expect
(
subject
).
to
be_persisted
end
end
end
...
...
@@ -125,6 +123,12 @@ describe CreateDeploymentService, services: true do
expect
(
Deployment
.
last
.
deployable
).
to
eq
(
deployable
)
end
it
'create environment has URL set'
do
subject
expect
(
Deployment
.
last
.
environment
.
external_url
).
not_to
be_nil
end
end
context
'without environment specified'
do
...
...
@@ -137,7 +141,10 @@ describe CreateDeploymentService, services: true do
context
'when environment is specified'
do
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
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