flutter_dotenv icon indicating copy to clipboard operation
flutter_dotenv copied to clipboard

using .env in codemagic

Open johnadvincula-ada opened this issue 4 years ago • 4 comments

Hi, I used this package and created a .env file and put in .gitignore. Now when I tried to used the codemagic CICD it gives me an error no file or variants found for asset .env. How do you solve this?

johnadvincula-ada avatar Nov 11 '21 10:11 johnadvincula-ada

I'm considering this package with the same question. @johnadvincula-ada, did you ever find a solution? I currently use environment_config, which works well with codemagic, but is pretty quirky otherwise.

mlars84 avatar Jan 06 '22 21:01 mlars84

@johnadvincula-ada There are a few approaches to this that depend on your needs.

One simple approach would be pre define all environment files in checked in files eg.

.env.prod // a checked in file containing all env vars for prod
.env.dev // a checked in file containing all env vars for dev

Then create a pre build step in your codemagic build workflow that contains a bash script that performs a rename to .env

On the prod workflow for example he bash script can run a rename on .env.prod to .env before build. And delete the .env.dev file.

java-james avatar Feb 15 '22 23:02 java-james

If you don't check in your .env file you need a way to provide it during build. In Codemagic or any other CI/CD you need to execute a kind of pre-build script.

First, base64 encode your whole .env file with its values. Then on the CI/CD run a simple script which base64 decodes and pipes everything into .env file like this echo "$ENV_FILE" | base64 --decode > .env where $ENV_FILE is your base64 encoded secret/local environment variable on CI/CD

That's it

MuTe33 avatar Mar 05 '22 14:03 MuTe33

I'm adding a pre-test script (click the settings cog in your workflow editor) that creates the file just before attempting the flutter build. echo "myVariable=myValue" >> assets/.env on build.

ecoant avatar Jun 02 '22 20:06 ecoant