I have some issues getting my env variables to change in Testflight while using react-native-codepush triggered by Azure pipeline. I do not have .env submitted to my repo, they're dynamically generated during pipeline. Caching should not be an issue as this is not run locally but directly from the Azure repo where node_modules etc is not present.
I have a useEffect in my HomeScreen where I log AUTH_DOMAIN, TAX, ENV and MAP_WIDGET_URL.
useEffect(() => {
alert({
title: 'Welcome',
message: `${AUTH_DOMAIN} ${TAX} ${ENV} ${MAP_WIDGET_URL}`,
type: 'info',
})
}, [])
Previously in my pipeline I did not have ENV and TAX, I added them for testing-purposes. Whenever I change them they're reflected in the app. This is not true for any of the pre-existing env variables however, and I do not understand why.
I tried setting e.g. AUTH_DOMAIN and MAP_WIDGET_URL to fixed values and not getting it from my pipeline-variables like this, which did not work. The first original values are still existing.
echo "AUTH_DOMAIN=AUTH_DOMAIN_TEST" > public/.env --> still shows old value
echo "MAP_WIDGET_URL=urrrrl" >> public/.env --> still shows old value
echo "ENV=NEW_VALUE" >> public/.env --> shows new value
My cat public/.env at end of pipeline always shows the correct values.
Can anyone see whats wrong?
module.exports = (api) => {
api.cache(true)
return {
presets: ['babel-preset-expo'],
plugins: [
'react-native-reanimated/plugin',
[
'module:react-native-dotenv',
{
moduleName: '@env',
path: './public/.env',
blacklist: null,
whitelist: null,
safe: false,
allowUndefined: true,
allowlist: [
'AUTH_DOMAIN',
'MAP_WIDGET_URL',
'CODE_PUSH_KEY_ANDROID',
'CODE_PUSH_KEY_IOS',
'TAX',
'ENV',
],
},
],
],
}
}
Env declaration:
declare module '@env' {
export const AUTH_DOMAIN: string
export const CODE_PUSH_KEY_ANDROID: string
export const CODE_PUSH_KEY_IOS: string
export const TAX: string
export const ENV: string
}
Pipeline:
trigger:
branches:
include:
- test
pool:
vmImage: 'ubuntu-latest'
jobs:
- job: CodePushTest
condition: eq(variables['Build.SourceBranch'], 'refs/heads/test')
steps:
- script: |
# Create the public directory if it doesn't exist
mkdir -p public
# Overwrite or create the .env file with the first variable
echo "AUTH_DOMAIN=${TEST_AUTH_DOMAIN}" > public/.env
# Append other variables
echo "MAP_WIDGET_URL=${TEST_MAP_WIDGET_URL}" >> public/.env
echo "CODE_PUSH_KEY_IOS=${CODE_PUSH_KEY_IOS_STAGING}" >> public/.env
echo "CODE_PUSH_KEY_ANDROID=${CODE_PUSH_KEY_ANDROID_STAGING}" >> public/.env
echo "ENV=TESTENV" >> public/.env
echo "TAX=TESTTAX" >> public/.env
cat public/.env
npm install -g appcenter-cli
yarn install
appcenter login --token $(APPCENTER_ACCESS)
appcenter codepush release-react -a NAME-iOS -d Staging
appcenter codepush release-react -a NAME-Android -d Staging
appcenter logout
displayName: 'Code Push Test'
My workflow prior to react-native-codepush was:
- Make changes to repo
- Appcenter gets triggered (I have env variables set here to also be generated dynamically)
- Pushes to Testflight with new env variables from the build configuration
- Works.
I've also tested:
- Change env variables in App center build configuration
- Rebuild while having codepush-disabled -> Works, correct env-variables in Testflight.
- Make a new update and do not rebuild, instead I let codepush do the update.
- After codepush update is applied -> overwrites the Appcenter builds env-variables and shows the old codepush env variables....