Gracefully handle duplicate dotenv keys

What does this MR do and why?

If a dotenv artifact contained the same key, CI artifact uploads would fail with 400 Bad Request. For example:

KEY1=test
KEY1=something

In a shell environment, we'd expect the latest value to overwrite the first one, so we now de-duplicate the dotenv keys and use the latest value.

This is consistent with how the original dotenv package works. Given an .env file and JavaScript test:

KEY=one
KEY=two
KEY=three
require('dotenv').config()

console.log(process.env.KEY)

The result:

$ node test.js
three

Relates to #288064

How to set up and validate locally

Run a CI job with https://gitlab.com/jrreid/duplicate-dotenv-test/-/blob/main/.gitlab-ci.yml.

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Stan Hu

Merge request reports

Loading