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
2b5b1406
Commit
2b5b1406
authored
Apr 15, 2021
by
Furkan Ayhan
Committed by
Gabriel Mazetto
Apr 15, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement wildcard support for pipeline include file paths [RUN ALL RSPEC] [RUN AS-IF-FOSS]
parent
288c7965
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
214 additions
and
0 deletions
+214
-0
config/feature_flags/development/ci_wildcard_file_paths.yml
config/feature_flags/development/ci_wildcard_file_paths.yml
+8
-0
doc/ci/yaml/README.md
doc/ci/yaml/README.md
+35
-0
lib/gitlab/ci/config/external/mapper.rb
lib/gitlab/ci/config/external/mapper.rb
+12
-0
qa/qa/specs/features/browser_ui/4_verify/pipeline/include_local_config_file_paths_with_wildcard_spec.rb
...ine/include_local_config_file_paths_with_wildcard_spec.rb
+90
-0
spec/lib/gitlab/ci/config/external/mapper_spec.rb
spec/lib/gitlab/ci/config/external/mapper_spec.rb
+34
-0
spec/lib/gitlab/ci/config/external/processor_spec.rb
spec/lib/gitlab/ci/config/external/processor_spec.rb
+35
-0
No files found.
config/feature_flags/development/ci_wildcard_file_paths.yml
0 → 100644
View file @
2b5b1406
---
name
:
ci_wildcard_file_paths
introduced_by_url
:
https://gitlab.com/gitlab-org/gitlab/-/merge_requests/58999
rollout_issue_url
:
https://gitlab.com/gitlab-org/gitlab/-/issues/327315
milestone
:
'
13.11'
type
:
development
group
:
group::pipeline authoring
default_enabled
:
false
doc/ci/yaml/README.md
View file @
2b5b1406
...
@@ -477,6 +477,41 @@ include: '.gitlab-ci-production.yml'
...
@@ -477,6 +477,41 @@ include: '.gitlab-ci-production.yml'
Use local includes instead of symbolic links.
Use local includes instead of symbolic links.
##### `include:local` with wildcard file paths
> - [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/25921) in GitLab 13.11.
> - It's [deployed behind a feature flag](../../user/feature_flags.md), disabled by default.
> - It's disabled on GitLab.com.
> - It's not recommended for production use.
> - To use it in GitLab self-managed instances, ask a GitLab administrator to enable it. **(CORE ONLY)**
You can use wildcard paths (
`*`
) with
`include:local`
.
Example:
```
yaml
include
:
'
configs/*.yml'
```
When the pipeline runs, it adds all
`.yml`
files in the
`configs`
folder into the pipeline configuration.
The wildcard file paths feature is under development and not ready for production use. It is
deployed behind a feature flag that is
**disabled by default**
.
[
GitLab administrators with access to the GitLab Rails console
](
../../administration/feature_flags.md
)
can enable it.
To enable it:
```
ruby
Feature
.
enable
(
:ci_wildcard_file_paths
)
```
To disable it:
```
ruby
Feature
.
disable
(
:ci_wildcard_file_paths
)
```
#### `include:file`
#### `include:file`
> [Introduced](https://gitlab.com/gitlab-org/gitlab-foss/-/issues/53903) in GitLab 11.7.
> [Introduced](https://gitlab.com/gitlab-org/gitlab-foss/-/issues/53903) in GitLab 11.7.
...
...
lib/gitlab/ci/config/external/mapper.rb
View file @
2b5b1406
...
@@ -34,6 +34,7 @@ module Gitlab
...
@@ -34,6 +34,7 @@ module Gitlab
.
compact
.
compact
.
map
(
&
method
(
:normalize_location
))
.
map
(
&
method
(
:normalize_location
))
.
flat_map
(
&
method
(
:expand_project_files
))
.
flat_map
(
&
method
(
:expand_project_files
))
.
flat_map
(
&
method
(
:expand_wildcard_paths
))
.
map
(
&
method
(
:expand_variables
))
.
map
(
&
method
(
:expand_variables
))
.
each
(
&
method
(
:verify_duplicates!
))
.
each
(
&
method
(
:verify_duplicates!
))
.
map
(
&
method
(
:select_first_matching
))
.
map
(
&
method
(
:select_first_matching
))
...
@@ -63,6 +64,17 @@ module Gitlab
...
@@ -63,6 +64,17 @@ module Gitlab
end
end
end
end
def
expand_wildcard_paths
(
location
)
return
location
unless
::
Feature
.
enabled?
(
:ci_wildcard_file_paths
,
context
.
project
,
default_enabled: :yaml
)
# We only support local files for wildcard paths
return
location
unless
location
[
:local
]
&&
location
[
:local
].
include?
(
'*'
)
context
.
project
.
repository
.
search_files_by_wildcard_path
(
location
[
:local
],
context
.
sha
).
map
do
|
path
|
{
local:
path
}
end
end
def
normalize_location_string
(
location
)
def
normalize_location_string
(
location
)
if
::
Gitlab
::
UrlSanitizer
.
valid?
(
location
)
if
::
Gitlab
::
UrlSanitizer
.
valid?
(
location
)
{
remote:
location
}
{
remote:
location
}
...
...
qa/qa/specs/features/browser_ui/4_verify/pipeline/include_local_config_file_paths_with_wildcard_spec.rb
0 → 100644
View file @
2b5b1406
# frozen_string_literal: true
module
QA
RSpec
.
describe
'Verify'
,
:requires_admin
do
describe
'Include local config file paths with wildcard'
do
let
(
:feature_flag
)
{
:ci_wildcard_file_paths
}
let
(
:project
)
do
Resource
::
Project
.
fabricate_via_api!
do
|
project
|
project
.
name
=
'project-with-pipeline'
end
end
before
do
Runtime
::
Feature
.
enable
(
feature_flag
)
Flow
::
Login
.
sign_in
add_files_to_project
project
.
visit!
Flow
::
Pipeline
.
visit_latest_pipeline
end
after
do
Runtime
::
Feature
.
disable
(
feature_flag
)
project
.
remove_via_api!
end
it
'runs the pipeline with composed config'
,
testcase:
'https://gitlab.com/gitlab-org/quality/testcases/-/issues/1757'
do
Page
::
Project
::
Pipeline
::
Show
.
perform
do
|
pipeline
|
aggregate_failures
'pipeline has all expected jobs'
do
expect
(
pipeline
).
to
have_job
(
'build'
)
expect
(
pipeline
).
to
have_job
(
'test'
)
expect
(
pipeline
).
not_to
have_job
(
'deploy'
)
end
end
end
private
def
add_files_to_project
Resource
::
Repository
::
Commit
.
fabricate_via_api!
do
|
commit
|
commit
.
project
=
project
commit
.
commit_message
=
'Add CI and local files'
commit
.
add_files
([
build_config_file
,
test_config_file
,
non_detectable_file
,
main_ci_file
])
end
end
def
main_ci_file
{
file_path:
'.gitlab-ci.yml'
,
content:
<<~
YAML
include: 'configs/*.yml'
YAML
}
end
def
build_config_file
{
file_path:
'configs/builds.yml'
,
content:
<<~
YAML
build:
stage: build
script: echo build
YAML
}
end
def
test_config_file
{
file_path:
'configs/tests.yml'
,
content:
<<~
YAML
test:
stage: test
script: echo test
YAML
}
end
def
non_detectable_file
{
file_path:
'configs/not_included.yaml'
,
# we only include `*.yml` not `*.yaml`
content:
<<~
YAML
deploy:
stage: deploy
script: echo deploy
YAML
}
end
end
end
end
spec/lib/gitlab/ci/config/external/mapper_spec.rb
View file @
2b5b1406
...
@@ -324,5 +324,39 @@ RSpec.describe Gitlab::Ci::Config::External::Mapper do
...
@@ -324,5 +324,39 @@ RSpec.describe Gitlab::Ci::Config::External::Mapper do
end
end
end
end
end
end
context
'when local file path has wildcard'
do
let
(
:project
)
{
create
(
:project
,
:repository
)
}
let
(
:values
)
do
{
include:
'myfolder/*.yml'
}
end
before
do
allow_next_instance_of
(
Repository
)
do
|
repository
|
allow
(
repository
).
to
receive
(
:search_files_by_wildcard_path
).
with
(
'myfolder/*.yml'
,
'123456'
)
do
[
'myfolder/file1.yml'
,
'myfolder/file2.yml'
]
end
end
end
it
'includes the matched local files'
do
expect
(
subject
).
to
contain_exactly
(
an_instance_of
(
Gitlab
::
Ci
::
Config
::
External
::
File
::
Local
),
an_instance_of
(
Gitlab
::
Ci
::
Config
::
External
::
File
::
Local
))
expect
(
subject
.
map
(
&
:location
)).
to
contain_exactly
(
'myfolder/file1.yml'
,
'myfolder/file2.yml'
)
end
context
'when the FF ci_wildcard_file_paths is disabled'
do
before
do
stub_feature_flags
(
ci_wildcard_file_paths:
false
)
end
it
'cannot find any file returns an error message'
do
expect
(
subject
).
to
contain_exactly
(
an_instance_of
(
Gitlab
::
Ci
::
Config
::
External
::
File
::
Local
))
expect
(
subject
[
0
].
errors
).
to
eq
([
'Local file `myfolder/*.yml` does not exist!'
])
end
end
end
end
end
end
end
spec/lib/gitlab/ci/config/external/processor_spec.rb
View file @
2b5b1406
...
@@ -366,5 +366,40 @@ RSpec.describe Gitlab::Ci::Config::External::Processor do
...
@@ -366,5 +366,40 @@ RSpec.describe Gitlab::Ci::Config::External::Processor do
expect
(
output
.
keys
).
to
match_array
([
:image
,
:my_build
,
:my_test
])
expect
(
output
.
keys
).
to
match_array
([
:image
,
:my_build
,
:my_test
])
end
end
end
end
context
'when local file path has wildcard'
do
let_it_be
(
:project
)
{
create
(
:project
,
:repository
)
}
let
(
:values
)
do
{
include:
'myfolder/*.yml'
,
image:
'ruby:2.7'
}
end
before
do
allow_next_instance_of
(
Repository
)
do
|
repository
|
allow
(
repository
).
to
receive
(
:search_files_by_wildcard_path
).
with
(
'myfolder/*.yml'
,
sha
)
do
[
'myfolder/file1.yml'
,
'myfolder/file2.yml'
]
end
allow
(
repository
).
to
receive
(
:blob_data_at
).
with
(
sha
,
'myfolder/file1.yml'
)
do
<<~
HEREDOC
my_build:
script: echo Hello World
HEREDOC
end
allow
(
repository
).
to
receive
(
:blob_data_at
).
with
(
sha
,
'myfolder/file2.yml'
)
do
<<~
HEREDOC
my_test:
script: echo Hello World
HEREDOC
end
end
end
it
'fetches the matched files'
do
output
=
processor
.
perform
expect
(
output
.
keys
).
to
match_array
([
:image
,
:my_build
,
:my_test
])
end
end
end
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