using .env in codemagic
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?
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.
@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.
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
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.