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
4f472d49
Commit
4f472d49
authored
Feb 27, 2018
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make pipeline priority variables concept explicit
parent
83bc2844
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
77 additions
and
14 deletions
+77
-14
build.rb
app/models/ci/build.rb
+2
-1
pipeline.rb
app/models/ci/pipeline.rb
+10
-6
project.rb
app/models/project.rb
+2
-1
build_spec.rb
spec/models/ci/build_spec.rb
+26
-0
pipeline_spec.rb
spec/models/ci/pipeline_spec.rb
+37
-6
No files found.
app/models/ci/build.rb
View file @
4f472d49
...
...
@@ -262,8 +262,9 @@ module Ci
variables
+=
secret_variables
(
environment:
environment
)
variables
+=
trigger_request
.
user_variables
if
trigger_request
variables
+=
persisted_environment_variables
if
environment
variables
+=
pipeline
.
priority_variables
variables
variables
.
reverse
.
uniq
{
|
variable
|
variable
.
fetch
(
:key
)
}.
reverse
end
def
features
...
...
app/models/ci/pipeline.rb
View file @
4f472d49
...
...
@@ -473,10 +473,9 @@ module Ci
end
def
predefined_variables
predefined
=
[
p
ipeline_p
redefined
=
[
{
key:
'CI'
,
value:
'true'
,
public:
true
},
{
key:
'GITLAB_CI'
,
value:
'true'
,
public:
true
},
{
key:
'GITLAB_FEATURES'
,
value:
project
.
namespace
.
features
.
join
(
','
),
public:
true
},
{
key:
'CI_SERVER_NAME'
,
value:
'GitLab'
,
public:
true
},
{
key:
'CI_SERVER_VERSION'
,
value:
Gitlab
::
VERSION
,
public:
true
},
{
key:
'CI_SERVER_REVISION'
,
value:
Gitlab
::
REVISION
,
public:
true
},
...
...
@@ -485,11 +484,16 @@ module Ci
{
key:
'CI_PIPELINE_SOURCE'
,
value:
source
.
to_s
,
public:
true
}
]
predefined
+=
project
.
predefined_variables
predefined
+=
pipeline_schedule
.
job_variables
if
pipeline_schedule
predefined
+=
self
.
variables
.
map
(
&
:to_runner_variable
)
Array
(
project
.
predefined_variables
)
+
pipeline_predefined
end
def
priority_variables
Array
(
pipeline_schedule
&
.
job_variables
)
+
self
.
variables
.
map
(
&
:to_runner_variable
)
end
predefined
def
runtime_variables
predefined_variables
+
priority_variables
end
def
queued_duration
...
...
app/models/project.rb
View file @
4f472d49
...
...
@@ -1589,7 +1589,8 @@ class Project < ActiveRecord::Base
{
key:
'CI_PROJECT_PATH_SLUG'
,
value:
full_path_slug
,
public:
true
},
{
key:
'CI_PROJECT_NAMESPACE'
,
value:
namespace
.
full_path
,
public:
true
},
{
key:
'CI_PROJECT_URL'
,
value:
web_url
,
public:
true
},
{
key:
'CI_PROJECT_VISIBILITY'
,
value:
Gitlab
::
VisibilityLevel
.
string_level
(
visibility_level
),
public:
true
}
{
key:
'CI_PROJECT_VISIBILITY'
,
value:
Gitlab
::
VisibilityLevel
.
string_level
(
visibility_level
),
public:
true
},
{
key:
'GITLAB_FEATURES'
,
value:
namespace
.
features
.
join
(
','
),
public:
true
}
]
variables
+=
container_registry_variables
...
...
spec/models/ci/build_spec.rb
View file @
4f472d49
...
...
@@ -1891,6 +1891,32 @@ describe Ci::Build do
end
end
end
context
'when there are duplicated variables present '
do
context
'when there are duplicated YAML variables'
do
before
do
build
.
yaml_variables
=
[{
key:
'MYVAR'
,
value:
'first'
,
public:
true
},
{
key:
'MYVAR'
,
value:
'second'
,
public:
true
}]
end
it
'keeps the last occurence of a variable by given key'
do
expect
(
subject
).
not_to
include
(
key:
'MYVAR'
,
value:
'first'
,
public:
true
)
expect
(
subject
).
to
include
(
key:
'MYVAR'
,
value:
'second'
,
public:
true
)
end
end
context
'when pipeline trigger variable overrides YAML variables'
do
before
do
build
.
yaml_variables
=
[{
key:
'MYVAR'
,
value:
'myvar'
,
public:
true
}]
pipeline
.
variables
.
build
(
key:
'MYVAR'
,
value:
'pipeline value'
)
end
it
'overrides YAML variable with a pipeline trigger variable'
do
expect
(
subject
).
not_to
include
(
key:
'MYVAR'
,
value:
'myvar'
,
public:
true
)
expect
(
subject
).
to
include
(
key:
'MYVAR'
,
value:
'pipeline value'
,
public:
false
)
end
end
end
end
describe
'state transition: any => [:pending]'
do
...
...
spec/models/ci/pipeline_spec.rb
View file @
4f472d49
...
...
@@ -167,15 +167,46 @@ describe Ci::Pipeline, :mailer do
end
end
describe
'#predefined_variables'
do
subject
{
pipeline
.
predefined_variables
}
describe
'pipeline variables'
do
describe
'#predefined_variables'
do
subject
{
pipeline
.
predefined_variables
}
it
{
is_expected
.
to
be_an
(
Array
)
}
it
{
is_expected
.
to
be_an
(
Array
)
}
it
'includes the defined keys'
do
keys
=
subject
.
map
{
|
v
|
v
.
fetch
(
:key
)
}
expect
(
keys
).
to
include
(
'CI_PIPELINE_ID'
,
'CI_CONFIG_PATH'
,
'CI_PIPELINE_SOURCE'
)
end
it
'includes project-level predefined variables'
do
keys
=
subject
.
map
{
|
v
|
v
.
fetch
(
:key
)
}
expect
(
keys
).
to
include
(
'CI_PROJECT_NAME'
)
end
end
describe
'#priority_variables'
do
before
do
pipeline
.
variables
.
build
(
key:
'MY_VAR'
,
value:
'my var'
)
end
it
'includes the defined keys'
do
keys
=
subject
.
map
{
|
v
|
v
[
:key
]
}
it
'returns trigger variables'
do
expect
(
pipeline
.
priority_variables
)
.
to
include
(
key:
'MY_VAR'
,
value:
'my var'
,
public:
false
)
end
end
expect
(
keys
).
to
include
(
'CI_PIPELINE_ID'
,
'CI_CONFIG_PATH'
,
'CI_PIPELINE_SOURCE'
)
describe
'#runtime_variables'
do
before
do
pipeline
.
variables
.
build
(
key:
'MY_VAR'
,
value:
'my var'
)
end
it
'includes predefined and priority variables'
do
variables
=
pipeline
.
runtime_variables
.
map
{
|
v
|
v
.
fetch
(
:key
)
}
expect
(
variables
).
to
include
(
'MY_VAR'
,
'CI_PIPELINE_ID'
,
'CI_PROJECT_ID'
)
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