question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Option to only load .env file env vars

See original GitHub issue

I’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:closed
  • Created 4 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
cdimasciocommented, Apr 30, 2019

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

Set<DotenvEntry> entriesInFile = dotenv.entries(DotenvEntriesFilter.DECLARED_IN_ENV_FILE);
0reactions
allcontributors[bot]commented, May 30, 2019

@cdimascio

I’ve put up a pull request to add @cdimascio! 🎉

Read more comments on GitHub >

github_iconTop Results From Across the Web

Load environment variables from dotenv / .env file in Bash
I have some long and unusually formatted environment variables, and this was the only solution which didn't choke on them.
Read more >
Using .env Files for Environment Variables in Python ...
load_dotenv () will first look for a .env file and if it finds one, it will load the environment variables from the file...
Read more >
Environment variables in Compose | Docker Documentation
The .env file feature only works when you use the docker-compose up command and does not work with docker stack deploy . Both...
Read more >
Env Variables and Modes - Vite
Vite uses dotenv to load additional environment variables from the following files in your ... [mode].local # only loaded in specified mode, ignored...
Read more >
dotenv file is not loading environment variables - Stack Overflow
You can create this path like this: const path = require('path') require('dotenv'). config({path: path. relative(process.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found