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
3d1ac58d
Commit
3d1ac58d
authored
Jan 14, 2022
by
lauraMon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove warning/error for duplicate includes
* Updates documentation
parent
7bfaf53b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
88 additions
and
21 deletions
+88
-21
doc/ci/yaml/includes.md
doc/ci/yaml/includes.md
+63
-0
lib/gitlab/ci/config/external/mapper.rb
lib/gitlab/ci/config/external/mapper.rb
+5
-9
spec/lib/gitlab/ci/config/external/mapper_spec.rb
spec/lib/gitlab/ci/config/external/mapper_spec.rb
+20
-12
No files found.
doc/ci/yaml/includes.md
View file @
3d1ac58d
...
...
@@ -217,6 +217,69 @@ default:
-
echo "Job complete."
```
### Use nested includes with duplicate `includes` entries
> [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/28987) in GitLab 14.8
Nested includes can include the same configuration file. The duplicate configuration
file is included multiple times, but the effect is the same as if it was only
included once.
For example, with the following nested includes, where
`defaults.gitlab-ci.yml`
is included multiple times:
-
Contents of the
`.gitlab-ci.yml`
file:
```
yaml
include
:
-
template
:
defaults.gitlab-ci.yml
-
local
:
unit-tests.gitlab-ci.yml
-
local
:
smoke-tests.gitlab-ci.yml
```
-
Contents of the
`defaults.gitlab-ci.yml`
file:
```
yaml
default
:
before_script
:
default-before-script.sh
retry
:
2
```
-
Contents of the
`unit-tests.gitlab-ci.yml`
file:
```
yaml
include
:
-
template
:
defaults.gitlab-ci.yml
unit-test-job
:
script
:
unit-test.sh
retry
:
0
```
-
Contents of the
`smoke-tests.gitlab-ci.yml`
file:
```
yaml
include
:
-
template
:
defaults.gitlab-ci.yml
smoke-test-job
:
script
:
smoke-test.sh
```
The final configuration would be:
```
yaml
unit-test-job
:
before_script
:
default-before-script.sh
script
:
unit-test.sh
retry
:
0
smoke-test-job
:
before_script
:
default-before-script.sh
script
:
smoke-test.sh
retry
:
2
```
## Use variables with `include`
> - [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/284883) in GitLab 13.8.
...
...
lib/gitlab/ci/config/external/mapper.rb
View file @
3d1ac58d
...
...
@@ -19,7 +19,6 @@ module Gitlab
Error
=
Class
.
new
(
StandardError
)
AmbigiousSpecificationError
=
Class
.
new
(
Error
)
DuplicateIncludesError
=
Class
.
new
(
Error
)
TooManyIncludesError
=
Class
.
new
(
Error
)
def
initialize
(
values
,
context
)
...
...
@@ -114,25 +113,22 @@ module Gitlab
def
verify_duplicates!
(
location
)
logger
.
instrument
(
:config_mapper_verify
)
do
verify_
duplicates_without_instrument
ation!
(
location
)
verify_
max_includes_and_add_loc
ation!
(
location
)
end
end
def
verify_
duplicates_without_instrument
ation!
(
location
)
def
verify_
max_includes_and_add_loc
ation!
(
location
)
if
expandset
.
count
>=
MAX_INCLUDES
raise
TooManyIncludesError
,
"Maximum of
#{
MAX_INCLUDES
}
nested includes are allowed!"
end
# We scope location to context, as this allows us to properly support
# relative includes, and similarly looking relative in another project
# does not trigger duplicate error
# Scope location to context to allow support of
# relative includes
scoped_location
=
location
.
merge
(
context_project:
context
.
project
,
context_sha:
context
.
sha
)
unless
expandset
.
add?
(
scoped_location
)
raise
DuplicateIncludesError
,
"Include `
#{
location
.
to_json
}
` was already included!"
end
expandset
.
add
(
scoped_location
)
end
def
select_first_matching
(
location
)
...
...
spec/lib/gitlab/ci/config/external/mapper_spec.rb
View file @
3d1ac58d
...
...
@@ -175,27 +175,35 @@ RSpec.describe Gitlab::Ci::Config::External::Mapper do
end
end
context
"when duplicate 'include' is defined"
do
context
"when duplicate 'include's are defined"
do
let
(
:values
)
do
{
include:
[
{
'local'
=>
local_file
},
{
'local'
=>
local_file
}
],
image:
'ruby:2.7'
}
end
it
'does not raise an exception'
do
expect
{
subject
}.
not_to
raise_error
end
end
context
'when passing max number of files'
do
let
(
:values
)
do
{
include:
[
{
'local'
=>
local_file
},
{
'
local'
=>
local_file
}
{
'
remote'
=>
remote_url
}
],
image:
'ruby:2.7'
}
end
it
'raises an exception'
do
expect
{
subject
}.
to
raise_error
(
described_class
::
DuplicateIncludesError
)
before
do
stub_const
(
"
#{
described_class
}
::MAX_INCLUDES"
,
2
)
end
context
'when including multiple files from a project'
do
let
(
:values
)
do
{
include:
{
project:
project
.
full_path
,
file:
[
local_file
,
local_file
]
}
}
end
it
'raises an exception'
do
expect
{
subject
}.
to
raise_error
(
described_class
::
DuplicateIncludesError
)
end
it
'does not raise an exception'
do
expect
{
subject
}.
not_to
raise_error
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