Skip to content

.env not working in CI/CD #93

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Navil opened this issue Dec 10, 2023 · 2 comments
Open

.env not working in CI/CD #93

Navil opened this issue Dec 10, 2023 · 2 comments

Comments

@Navil
Copy link

Navil commented Dec 10, 2023

I am having a CI/CD pipeline using GitHub actions. The .env file seems not to be picked up correctly there.
Everything works fine on my machine when I run the app. Also wenn I build the AppBundle, the .env file is in there.

For my own sanity check, I added a step in my pipeline to list the directory and the file is there and has the correct filesize:
image

However, when I try to access anything (e.g. static final isProduction = dotenv.env["IS_PRODUCTION"]), the value is basically undefined.
My main method looks like this:

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await dotenv.load();
  ...

No error is thrown when I am loading the file itself, but the content seems not to be there.
I am adding the .env file via a secret:

  - name: Add ENV
        env:
          ENV_FILE_CONTENT: ${{ secrets.ENV }}
        run: |
          echo $ENV_FILE_CONTENT > .env

But as shown in the directory step, the file seems to exist and as await dotenv.load(); doesn't throw an error, the file seems to work, but I just cant read data from it apparently.

@sirkev
Copy link

sirkev commented Jan 17, 2024

had the same issue, but got it resolved by passing in the file name when loading the .env
await dotenv.load(fileName: '.env'); WidgetsFlutterBinding.ensureInitialized(); await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform); runApp(const MyApp());

also in my script

- uses: actions/checkout@v3 - uses: subosito/flutter-action@v2 with: flutter-version: '3.16.7' channel: 'stable' - name: Make envfile uses: SpicyPizza/[email protected] with: envkey_ENVIRONMENT: ${{ secrets.ENVIRONMENT }} envkey_API_URL: ${{ secrets.API_URL }} file_name: .env

@manuelzzz
Copy link

Can anyone that tested it tell me if this solves the problem?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants