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
88ba7a03
Commit
88ba7a03
authored
May 25, 2017
by
Lin Jen-Shin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Pass external_url from environment if job doesn't have one
Also update the document and add a changelog entry
parent
86cd09f5
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
52 additions
and
13 deletions
+52
-13
app/models/ci/build.rb
app/models/ci/build.rb
+9
-3
changelogs/unreleased/25680-CI_ENVIRONMENT_URL.yml
changelogs/unreleased/25680-CI_ENVIRONMENT_URL.yml
+4
-0
doc/ci/environments.md
doc/ci/environments.md
+6
-0
doc/ci/variables/README.md
doc/ci/variables/README.md
+1
-0
spec/models/ci/build_spec.rb
spec/models/ci/build_spec.rb
+32
-10
No files found.
app/models/ci/build.rb
View file @
88ba7a03
...
...
@@ -501,9 +501,15 @@ module Ci
def
persisted_environment_variables
variables
=
persisted_environment
.
predefined_variables
variables
<<
{
key:
'CI_ENVIRONMENT_URL'
,
value:
expanded_environment_url
,
public:
true
}
if
environment_url
if
environment_url
variables
<<
{
key:
'CI_ENVIRONMENT_URL'
,
value:
expanded_environment_url
,
public:
true
}
elsif
persisted_environment
.
external_url
.
present?
variables
<<
{
key:
'CI_ENVIRONMENT_URL'
,
value:
persisted_environment
.
external_url
,
public:
true
}
end
variables
end
...
...
changelogs/unreleased/25680-CI_ENVIRONMENT_URL.yml
0 → 100644
View file @
88ba7a03
---
title
:
Add $CI_ENVIRONMENT_URL to predefined variables for pipelines
merge_request
:
11695
author
:
doc/ci/environments.md
View file @
88ba7a03
...
...
@@ -94,6 +94,12 @@ the name given in `.gitlab-ci.yml` (with any variables expanded), while the
second is a "cleaned-up" version of the name, suitable for use in URLs, DNS,
etc.
>**Note:**
Starting with GitLab 9.3, the environment URL is exposed to the Runner via
`$CI_ENVIRONMENT_URL`
. The URL would be expanded from
`.gitlab-ci.yml`
, or if
the URL was not defined there, the external URL from the environment would be
used.
To sum up, with the above
`.gitlab-ci.yml`
we have achieved that:
-
All branches will run the
`test`
and
`build`
jobs.
...
...
doc/ci/variables/README.md
View file @
88ba7a03
...
...
@@ -43,6 +43,7 @@ future GitLab releases.**
|
**CI_DEBUG_TRACE**
| all | 1.7 | Whether
[
debug tracing
](
#debug-tracing
)
is enabled |
|
**CI_ENVIRONMENT_NAME**
| 8.15 | all | The name of the environment for this job |
|
**CI_ENVIRONMENT_SLUG**
| 8.15 | all | A simplified version of the environment name, suitable for inclusion in DNS, URLs, Kubernetes labels, etc. |
|
**CI_ENVIRONMENT_URL**
| 9.3 | all | The URL of the environment for this job |
|
**CI_JOB_ID**
| 9.0 | all | The unique id of the current job that GitLab CI uses internally |
|
**CI_JOB_MANUAL**
| 8.12 | all | The flag to indicate that job was manually started |
|
**CI_JOB_NAME**
| 9.0 | 0.5 | The name of the job as defined in
`.gitlab-ci.yml`
|
...
...
spec/models/ci/build_spec.rb
View file @
88ba7a03
...
...
@@ -20,7 +20,7 @@ describe Ci::Build, :models do
it
{
is_expected
.
to
validate_presence_of
(
:ref
)
}
it
{
is_expected
.
to
respond_to
(
:has_trace?
)
}
it
{
is_expected
.
to
respond_to
(
:trace
)
}
it
{
is_expected
.
to
validate_length_of
(
:e
xternal
_url
).
is_at_most
(
255
)
}
it
{
is_expected
.
to
validate_length_of
(
:e
nvironment
_url
).
is_at_most
(
255
)
}
describe
'#actionize'
do
context
'when build is a created'
do
...
...
@@ -1208,33 +1208,55 @@ describe Ci::Build, :models do
]
end
let!
(
:environment
)
do
create
(
:environment
,
project:
build
.
project
,
name:
'production'
,
slug:
'prod-slug'
,
external_url:
''
)
end
before
do
build
.
update
(
environment:
'production'
)
create
(
:environment
,
project:
build
.
project
,
name:
'production'
,
slug:
'prod-slug'
)
end
context
'when no URL was set
'
do
shared_examples
'containing environment variables
'
do
it
{
environment_variables
.
each
{
|
v
|
is_expected
.
to
include
(
v
)
}
}
end
context
'when no URL was set'
do
it_behaves_like
'containing environment variables'
it
'does not have CI_ENVIRONMENT_URL'
do
keys
=
subject
.
map
{
|
var
|
var
[
:key
]
}
expect
(
keys
).
to
include
(
'CI_ENVIRONMENT_NAME'
,
'CI_ENVIRONMENT_SLUG'
)
expect
(
keys
).
not_to
include
(
'CI_ENVIRONMENT_URL'
)
end
end
context
'when an URL was set'
do
before
do
build
.
update
(
environment_url:
'http://host/$CI_JOB_NAME'
)
let
(
:url
)
{
'http://host/test'
}
before
do
environment_variables
<<
{
key:
'CI_ENVIRONMENT_URL'
,
value:
'http://host/test'
,
public:
true
}
{
key:
'CI_ENVIRONMENT_URL'
,
value:
url
,
public:
true
}
end
it
{
environment_variables
.
each
{
|
v
|
is_expected
.
to
include
(
v
)
}
}
context
'when the URL was set from the job'
do
before
do
build
.
update
(
environment_url:
'http://host/$CI_JOB_NAME'
)
end
it_behaves_like
'containing environment variables'
end
context
'when the URL was not set from the job, but environment'
do
before
do
environment
.
update
(
external_url:
url
)
end
it_behaves_like
'containing environment variables'
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