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
Léo-Paul Géneau
gitlab-ce
Commits
0d3631ac
Commit
0d3631ac
authored
Jun 21, 2017
by
Lin Jen-Shin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move expanded_environment_url to CreateDeploymentService
Because that's the only place we need it.
parent
df095d7d
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
57 additions
and
58 deletions
+57
-58
app/models/ci/build.rb
app/models/ci/build.rb
+9
-21
app/services/create_deployment_service.rb
app/services/create_deployment_service.rb
+12
-1
spec/models/ci/build_spec.rb
spec/models/ci/build_spec.rb
+0
-36
spec/services/create_deployment_service_spec.rb
spec/services/create_deployment_service_spec.rb
+36
-0
No files found.
app/models/ci/build.rb
View file @
0d3631ac
...
...
@@ -138,17 +138,6 @@ module Ci
ExpandVariables
.
expand
(
environment
,
simple_variables
)
if
environment
end
def
expanded_environment_url
return
@expanded_environment_url
if
defined?
(
@expanded_environment_url
)
@expanded_environment_url
=
if
unexpanded_url
=
environment_url
ExpandVariables
.
expand
(
unexpanded_url
,
simple_variables
)
else
persisted_environment
&
.
external_url
end
end
def
has_environment?
environment
.
present?
end
...
...
@@ -482,15 +471,10 @@ module Ci
variables
=
persisted_environment
.
predefined_variables
if
url
=
environment_url
# Note that CI_ENVIRONMENT_URL should be the last variable, because
# here we're passing unexpanded environment_url for runner to expand,
# and the runner would expand in order. In order to make sure that
# CI_ENVIRONMENT_URL has everything available, such as variables
# from Environment#predefined_variables, we need to make sure it's
# the last variable.
variables
<<
{
key:
'CI_ENVIRONMENT_URL'
,
value:
url
,
public:
true
}
end
# Here we're passing unexpanded environment_url for runner to expand,
# and we need to make sure that CI_ENVIRONMENT_NAME and
# CI_ENVIRONMENT_SLUG so on are available for the URL be expanded.
variables
<<
{
key:
'CI_ENVIRONMENT_URL'
,
value:
environment_url
,
public:
true
}
if
environment_url
variables
end
...
...
@@ -514,7 +498,11 @@ module Ci
end
def
environment_url
options
&
.
dig
(
:environment
,
:url
)
return
@environment_url
if
defined?
(
@environment_url
)
@environment_url
=
options
&
.
dig
(
:environment
,
:url
)
||
persisted_environment
&
.
external_url
end
def
build_attributes_from_config
...
...
app/services/create_deployment_service.rb
View file @
0d3631ac
...
...
@@ -2,7 +2,7 @@ class CreateDeploymentService
attr_reader
:job
delegate
:expanded_environment_name
,
:
expanded_environment_url
,
:
simple_variables
,
:project
,
to: :job
...
...
@@ -50,6 +50,17 @@ class CreateDeploymentService
@environment_options
||=
job
.
options
&
.
dig
(
:environment
)
||
{}
end
def
expanded_environment_url
return
@expanded_environment_url
if
defined?
(
@expanded_environment_url
)
@expanded_environment_url
=
if
unexpanded_url
=
environment_options
[
:url
]
ExpandVariables
.
expand
(
unexpanded_url
,
simple_variables
)
else
environment
&
.
external_url
end
end
def
on_stop
environment_options
[
:on_stop
]
end
...
...
spec/models/ci/build_spec.rb
View file @
0d3631ac
...
...
@@ -451,42 +451,6 @@ describe Ci::Build, :models do
end
end
describe
'#expanded_environment_url'
do
subject
{
job
.
expanded_environment_url
}
context
'when yaml environment uses $CI_COMMIT_REF_NAME'
do
let
(
:job
)
do
create
(
:ci_build
,
ref:
'master'
,
options:
{
environment:
{
url:
'http://review/$CI_COMMIT_REF_NAME'
}
})
end
it
{
is_expected
.
to
eq
(
'http://review/master'
)
}
end
context
'when yaml environment uses yaml_variables containing symbol keys'
do
let
(
:job
)
do
create
(
:ci_build
,
yaml_variables:
[{
key: :APP_HOST
,
value:
'host'
}],
options:
{
environment:
{
url:
'http://review/$APP_HOST'
}
})
end
it
{
is_expected
.
to
eq
(
'http://review/host'
)
}
end
context
'when yaml environment does not have url'
do
let
(
:job
)
{
create
(
:ci_build
,
environment:
'staging'
)
}
let!
(
:environment
)
do
create
(
:environment
,
project:
job
.
project
,
name:
job
.
environment
)
end
it
'returns the external_url from persisted environment'
do
is_expected
.
to
eq
(
environment
.
external_url
)
end
end
end
describe
'#starts_environment?'
do
subject
{
build
.
starts_environment?
}
...
...
spec/services/create_deployment_service_spec.rb
View file @
0d3631ac
...
...
@@ -122,6 +122,42 @@ describe CreateDeploymentService, services: true do
end
end
describe
'#expanded_environment_url'
do
subject
{
service
.
send
(
:expanded_environment_url
)
}
context
'when yaml environment uses $CI_COMMIT_REF_NAME'
do
let
(
:job
)
do
create
(
:ci_build
,
ref:
'master'
,
options:
{
environment:
{
url:
'http://review/$CI_COMMIT_REF_NAME'
}
})
end
it
{
is_expected
.
to
eq
(
'http://review/master'
)
}
end
context
'when yaml environment uses yaml_variables containing symbol keys'
do
let
(
:job
)
do
create
(
:ci_build
,
yaml_variables:
[{
key: :APP_HOST
,
value:
'host'
}],
options:
{
environment:
{
url:
'http://review/$APP_HOST'
}
})
end
it
{
is_expected
.
to
eq
(
'http://review/host'
)
}
end
context
'when yaml environment does not have url'
do
let
(
:job
)
{
create
(
:ci_build
,
environment:
'staging'
)
}
let!
(
:environment
)
do
create
(
:environment
,
project:
job
.
project
,
name:
job
.
environment
)
end
it
'returns the external_url from persisted environment'
do
is_expected
.
to
eq
(
environment
.
external_url
)
end
end
end
describe
'processing of builds'
do
shared_examples
'does not create deployment'
do
it
'does not create a new 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