I have build and distributed my iOS app using fastlane, for that I have created script in fast file, so now I want pass the env variable in this script for creating the template, this same template I can use my other iOS apps as well, so how can I pass env variables in my fastlane script?
Fastfile and Co are just Ruby code, so you can use ENV['XYZ'] to access any environment variables.
To set environment variables, there are multiple options in fastlane. Some are described at https://docs.fastlane.tools/advanced/other/#environment-variables
Fastlane also supports dotenv to set environment variables via files: https://docs.fastlane.tools/best-practices/keys/#dotenv
Related
I'm wondering how can I set up the MS AppCenter to use the specific .env file, let' say the .env.staging for example:
and the CI/CD of the AppCenter will do the build for me with that .env file
If you have separate branches for staging, release etc. this can be made to work.
For each of the branches have a common environment variable to identify the specific release. Ex: TARGET = staging
(Or you can even use Appcente's pre-defined variable APPCENTER_BRANCH to grab the branch name. Depends on the strategy you follow.)
Next create a either a appcenter-pre-build.sh or appcenter-post-build.sh and update it as follows. This will create a copy of your TARGET env file as .env
#!/usr/bin/env bash
# Appcenter pre-build hook to setup amplify.
set -e
IFS='|'
echo "Making a copy of .env file"
cp .env.${TARGET} .env
I have a Vue.js app hosted by AWS Amplify.
In Vue, env vars can be set application-wide by using .env. files.
I currently use such files for development and for production modes, containing different values.
When locally building and serving my application the above works as expected. However, once Amplify deploys my app (in my case I use Amplify's CD feature), these variables are not defined.
I know I can define the same env vars in Amplify, but that would mean I need to manage these values in two places since won't be redeploying while developing. so this seems to be prone to errors (I will need to remember to update the vars on both the application end and amplify console whenever I need to make a change for example).
I wonder if this behavior is expected or is there something I am missing in my setup.
Thanks!
I was also facing the same issue in my React app.
The thing is, you need to have a .env file in your app with all the environment variables.
Why? — The reason behind that is, it generates static HTML, CSS and JS files. Those files can't access process during the runtime.
After adding all the environment variables in Amplify, you have to add one more command in your build stage in App build specification.
You can refer to this official documentation on how to implement this.
If you don't care much about your environment variables, you can use this hack: printenv. This will store all the environment variables of your OS and your application in the .env file.
My config looks something like this:
build:
commands:
- 'printenv >> .env'
- 'npm run build'
I'm working on a VueJS app that uses env vars in multiple places. It runs on GCloud with nginx serving the files compiled with vue-cli-service build.
When developing everything works well with the env vars set in .env.development and .env.development.local files and used in JS with process.env.VUE_APP_FOO. I'm not using .env.production as some of these env vars shouldn't be committed to our repository.
For the staging and prod environment of all of our projects, we use GCloud's config maps which let us provide env vars to the pods. The issue in this project is that vue-cli-service build requires the env vars to be available at build time, which is not the case in our setup. Config maps are only available in the pods that run the images.
Out of curiosity, I checked the compiled code and all uses of process.env are quite simply replaced by an object with all vue env vars (basic ones + VUE_APP_* ones). So for example,
console.log(process.env.VUE_APP_FOO);
is compiled to
console.log(Object({NODE_ENV: "production", BASE_URL: "/", VUE_APP_FOO: "bar"}).VUE_APP_FOO);
Except that in our case, VUE_APP_FOO is missing from the object as it's not available in the environment when building the app.
So as is, it doesn't seem possible to provide env vars when the server is started or the JS file is served. Is there a way to tell vue-cli-service to not compile the env that way? Or any other alternative?
The only one I found so far is to replace the uses of env vars with their actual value directly in the compiled JS file when the pod starts using sed, but that's pretty ugly and could break easily.
One approach you can follow is to provide the production values when building locally. Another approach is to setup a continuous integration workflow that fetches your environment variables from wherever it is stored, builds the apps and pushes to production servers. I personally work with approach 2.
It is relatively easy to setup a github workflow that runs whenever your code is pushed to a particlar branch
I'm using react-native-config for setting environment variables in my react-native app. Now I want to use the ENV environment variable in the babel.config.js file to apply a plugin only when running the app in production. Basically what I want to do is apply a babel plugin only when running in production. Is this the correct way to achieve my goal?
How can I use the variable in the babel.config.js file? I tried importing Config from the react-native-config package and tried to access the variable via Config.ENV but that doesn't seem to work.
Is there a possibility to access environment variables through Chrome inspector?
Thank you
By default, no environment variables are exposed to the compiled client-side application.
But you can selectively include variables to your code by hand, e.g. inside HTML comments or console log outputs.
See also Vue CLI: Using Env Variables in Client-side Code:
You can access env variables in your application code:
console.log(process.env.VUE_APP_SECRET)
During build, process.env.VUE_APP_SECRET will be replaced by the corresponding value. In the case of VUE_APP_SECRET=secret, it will be replaced by "secret".