Option to only load .env file env vars
See original GitHub issueI’m using this dotenv
Java implementation in a scripted Jenkins pipeline and would like to load env vars from a CI env vars file we pull down from S3.
Apologies if this is stated somewhere in the code or documentation (I poked around extensively, but could not find anything). I would like to only load env vars from a .env
file and not mix them w/ system/host env vars.
I have this:
@Grab('io.github.cdimascio:java-dotenv:5.0.1')
import io.github.cdimascio.dotenv.Dotenv
import io.github.cdimascio.dotenv.DotenvEntry
Dotenv dotenv = Dotenv.configure()
.filename("ci-env-file-test")
.ignoreIfMissing()
.load()
for (DotenvEntry e : dotenv.entries()) {
System.out.println("${e.getKey()}=${e.getValue()}")
}
This outputs the env vars in my test CI env vars file, but also mixes them with my system/host env vars. I see the use case for this, for sure. I also saw: https://github.com/cdimascio/java-dotenv/issues/25, which seems to imply the dotenv.entries()
in v5.0.0
and below would do what I want, but @Grab
’ing that version (w/ my code above) still returns the env vars from my CI test file and my system/host env vars.
Am I missing a param I can pass to the configure .load()
… or?
ps: this is a great lib!
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (4 by maintainers)
A fix has been delivered to v5.1.0. It should be available on MavenCentral within 24 hours or so
You can make the following call to retrieve only entries defined in the
.env
file@cdimascio
I’ve put up a pull request to add @cdimascio! 🎉