Creating a local .env file

How to create a local .env file

You can create a .env file during the build process by adding a script in the pre-build phase of the Workflow editor or within your yaml file. This script will generate a local .env file and populate it with the necessary variables during the build.

scripts:
    - name: Create local .env file
      script: | 
        echo "MY_VAR=$MY_VAR" > .env
        echo "ANOTHER_VAR=$MY_ANOTHER_VAR" >> .env
        echo "AND_ANOTHER_VAR=$AND_ANOTHER_VAR" >> .env
NOTE: using >> after the first line appends lines to the file

The variables with $ in the above script can be imported from Codemagic UI. For more details, refer to this document.

For Windows, Powershell requires a different command for this case:

cmd.exe /c "echo "MY_VAR=$env:VAR_NAME" > .env"