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
2e5b4dbf
Commit
2e5b4dbf
authored
Dec 14, 2021
by
Stan Hu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Gracefully handle duplicate dotenv keys
parent
269db476
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
3 deletions
+34
-3
app/services/ci/parse_dotenv_artifact_service.rb
app/services/ci/parse_dotenv_artifact_service.rb
+3
-3
doc/ci/yaml/artifacts_reports.md
doc/ci/yaml/artifacts_reports.md
+5
-0
spec/services/ci/parse_dotenv_artifact_service_spec.rb
spec/services/ci/parse_dotenv_artifact_service_spec.rb
+26
-0
No files found.
app/services/ci/parse_dotenv_artifact_service.rb
View file @
2e5b4dbf
...
...
@@ -33,13 +33,13 @@ module Ci
end
def
parse!
(
artifact
)
variables
=
[]
variables
=
{}
artifact
.
each_blob
do
|
blob
|
blob
.
each_line
do
|
line
|
key
,
value
=
scan_line!
(
line
)
variables
<<
Ci
::
JobVariable
.
new
(
job_id:
artifact
.
job_id
,
variables
[
key
]
=
Ci
::
JobVariable
.
new
(
job_id:
artifact
.
job_id
,
source: :dotenv
,
key:
key
,
value:
value
)
end
end
...
...
@@ -49,7 +49,7 @@ module Ci
"Dotenv files cannot have more than
#{
dotenv_variable_limit
}
variables"
end
variables
variables
.
values
end
def
scan_line!
(
line
)
...
...
doc/ci/yaml/artifacts_reports.md
View file @
2e5b4dbf
...
...
@@ -169,6 +169,11 @@ The `dotenv` report collects a set of environment variables as artifacts.
The collected variables are registered as runtime-created variables of the job,
which you can use to
[
set dynamic environment URLs after a job finishes
](
../environments/index.md#set-dynamic-environment-urls-after-a-job-finishes
)
.
If duplicate environment variables are present in a
`dotenv`
report:
-
In GitLab 14.6 and later, the last one specified is used.
-
In GitLab 14.5 and earlier, an error occurs.
The exceptions to the
[
original dotenv rules
](
https://github.com/motdotla/dotenv#rules
)
are:
-
The variable key can contain only letters, digits, and underscores (
`_`
).
...
...
spec/services/ci/parse_dotenv_artifact_service_spec.rb
View file @
2e5b4dbf
...
...
@@ -37,6 +37,32 @@ RSpec.describe Ci::ParseDotenvArtifactService do
end
end
context
'when dotenv variables have duplicate variables'
do
let!
(
:artifact
)
{
create
(
:ci_job_artifact
,
:dotenv
,
job:
build
)
}
let
(
:blob
)
do
<<~
EOS
KEY1=VAR1
KEY2=VAR2
KEY2=VAR3
KEY1=VAR4
EOS
end
before
do
allow
(
artifact
).
to
receive
(
:each_blob
).
and_yield
(
blob
)
end
it
'latest values get used'
do
subject
expect
(
subject
[
:status
]).
to
eq
(
:success
)
expect
(
build
.
job_variables
.
as_json
).
to
contain_exactly
(
hash_including
(
'key'
=>
'KEY1'
,
'value'
=>
'VAR4'
),
hash_including
(
'key'
=>
'KEY2'
,
'value'
=>
'VAR3'
))
end
end
context
'when parse error happens'
do
before
do
allow
(
service
).
to
receive
(
:scan_line!
)
{
raise
described_class
::
ParserError
,
'Invalid Format'
}
...
...
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