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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
dfa6e574
Commit
dfa6e574
authored
Jul 15, 2021
by
Andrei Merfu
Committed by
Fabio Pitino
Jul 15, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Evaluate the variables for runner tags section
parent
983fe9da
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
169 additions
and
0 deletions
+169
-0
lib/gitlab/ci/pipeline/seed/build.rb
lib/gitlab/ci/pipeline/seed/build.rb
+11
-0
spec/lib/gitlab/ci/pipeline/seed/build_spec.rb
spec/lib/gitlab/ci/pipeline/seed/build_spec.rb
+14
-0
spec/services/ci/create_pipeline_service/evaluate_runner_tags_spec.rb
...s/ci/create_pipeline_service/evaluate_runner_tags_spec.rb
+144
-0
No files found.
lib/gitlab/ci/pipeline/seed/build.rb
View file @
dfa6e574
...
@@ -67,6 +67,7 @@ module Gitlab
...
@@ -67,6 +67,7 @@ module Gitlab
.
deep_merge
(
rules_attributes
)
.
deep_merge
(
rules_attributes
)
.
deep_merge
(
allow_failure_criteria_attributes
)
.
deep_merge
(
allow_failure_criteria_attributes
)
.
deep_merge
(
@cache
.
cache_attributes
)
.
deep_merge
(
@cache
.
cache_attributes
)
.
deep_merge
(
runner_tags
)
end
end
def
bridge?
def
bridge?
...
@@ -202,6 +203,16 @@ module Gitlab
...
@@ -202,6 +203,16 @@ module Gitlab
end
end
end
end
def
runner_tags
{
tag_list:
evaluate_runner_tags
}.
compact
end
def
evaluate_runner_tags
@seed_attributes
[
:tag_list
]
&
.
map
do
|
tag
|
ExpandVariables
.
expand_existing
(
tag
,
evaluate_context
.
variables
)
end
end
# If a job uses `allow_failure:exit_codes` and `rules:allow_failure`
# If a job uses `allow_failure:exit_codes` and `rules:allow_failure`
# we need to prevent the exit codes from being persisted because they
# we need to prevent the exit codes from being persisted because they
# would break the behavior defined by `rules:allow_failure`.
# would break the behavior defined by `rules:allow_failure`.
...
...
spec/lib/gitlab/ci/pipeline/seed/build_spec.rb
View file @
dfa6e574
...
@@ -90,6 +90,20 @@ RSpec.describe Gitlab::Ci::Pipeline::Seed::Build do
...
@@ -90,6 +90,20 @@ RSpec.describe Gitlab::Ci::Pipeline::Seed::Build do
end
end
end
end
context
'with job:tags'
do
let
(
:attributes
)
do
{
name:
'rspec'
,
ref:
'master'
,
job_variables:
[{
key:
'VARIABLE'
,
value:
'value'
,
public:
true
}],
tag_list:
[
'static-tag'
,
'$VARIABLE'
,
'$NO_VARIABLE'
]
}
end
it
{
is_expected
.
to
include
(
tag_list:
[
'static-tag'
,
'value'
,
'$NO_VARIABLE'
])
}
it
{
is_expected
.
to
include
(
yaml_variables:
[{
key:
'VARIABLE'
,
value:
'value'
,
public:
true
}])
}
end
context
'with cache:key'
do
context
'with cache:key'
do
let
(
:attributes
)
do
let
(
:attributes
)
do
{
{
...
...
spec/services/ci/create_pipeline_service/evaluate_runner_tags_spec.rb
0 → 100644
View file @
dfa6e574
# frozen_string_literal: true
require
'spec_helper'
RSpec
.
describe
Ci
::
CreatePipelineService
do
let_it_be
(
:group
)
{
create
(
:group
,
:private
)
}
let_it_be
(
:group_variable
)
{
create
(
:ci_group_variable
,
group:
group
,
key:
'RUNNER_TAG'
,
value:
'group'
)}
let_it_be
(
:project
)
{
create
(
:project
,
:repository
,
group:
group
)
}
let_it_be
(
:user
)
{
create
(
:user
)
}
let
(
:service
)
{
described_class
.
new
(
project
,
user
,
ref:
'master'
)
}
let
(
:pipeline
)
{
service
.
execute
(
:push
)
}
let
(
:job
)
{
pipeline
.
builds
.
find_by
(
name:
'job'
)
}
before
do
project
.
add_developer
(
user
)
stub_ci_pipeline_yaml_file
config
end
context
'when the variable is set'
do
let
(
:config
)
do
<<~
EOS
variables:
KUBERNETES_RUNNER: kubernetes
job:
tags:
- docker
- $KUBERNETES_RUNNER
script:
- echo "Hello runner selector feature"
EOS
end
it
'uses the evaluated variable'
do
expect
(
pipeline
).
to
be_created_successfully
expect
(
job
.
tags
.
pluck
(
:name
)).
to
match_array
(
%w[docker kubernetes]
)
end
end
context
'when the tag is composed by two variables'
do
let
(
:config
)
do
<<~
EOS
variables:
CLOUD_PROVIDER: aws
KUBERNETES_RUNNER: kubernetes
ENVIRONMENT_NAME: prod
job:
tags:
- docker
- $CLOUD_PROVIDER-$KUBERNETES_RUNNER-$ENVIRONMENT_NAME
script:
- echo "Hello runner selector feature"
EOS
end
it
'uses the evaluated variables'
do
expect
(
pipeline
).
to
be_created_successfully
expect
(
job
.
tags
.
pluck
(
:name
)).
to
match_array
(
%w[docker aws-kubernetes-prod]
)
end
end
context
'when the variable is not set'
do
let
(
:config
)
do
<<~
EOS
job:
tags:
- docker
- $KUBERNETES_RUNNER
script:
- echo "Hello runner selector feature"
EOS
end
it
'uses the variable as a regular string'
do
expect
(
pipeline
).
to
be_created_successfully
expect
(
job
.
tags
.
pluck
(
:name
)).
to
match_array
(
%w[docker $KUBERNETES_RUNNER]
)
end
end
context
'when the tag uses group variables'
do
let
(
:config
)
do
<<~
EOS
job:
tags:
- docker
- $RUNNER_TAG
script:
- echo "Hello runner selector feature"
EOS
end
it
'uses the evaluated variables'
do
expect
(
pipeline
).
to
be_created_successfully
expect
(
job
.
tags
.
pluck
(
:name
)).
to
match_array
(
%w[docker group]
)
end
end
context
'when the tag has the same variable name defined for both group and project'
do
let_it_be
(
:project_variable
)
{
create
(
:ci_variable
,
project:
project
,
key:
'RUNNER_TAG'
,
value:
'project'
)
}
let
(
:config
)
do
<<~
EOS
variables:
RUNNER_TAG: pipeline
job:
tags:
- docker
- $RUNNER_TAG
script:
- echo "Hello runner selector feature"
EOS
end
it
'uses the project variable instead of group due to variable precedence'
do
expect
(
pipeline
).
to
be_created_successfully
expect
(
job
.
tags
.
pluck
(
:name
)).
to
match_array
(
%w[docker project]
)
end
end
context
'with parallel:matrix config'
do
let
(
:tags
)
{
pipeline
.
builds
.
map
(
&
:tags
).
flatten
.
pluck
(
:name
)
}
let
(
:config
)
do
<<~
EOS
job:
parallel:
matrix:
- PROVIDER: [aws, gcp]
STACK: [monitoring, backup, app]
tags:
- ${PROVIDER}-${STACK}
script:
- echo "Hello runner selector feature"
EOS
end
it
'uses the evaluated variables'
do
expect
(
pipeline
).
to
be_created_successfully
expect
(
tags
).
to
match_array
(
%w[aws-monitoring aws-backup aws-app gcp-monitoring gcp-backup gcp-app]
)
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