The specific method used to set environment variables will vary by CI service, build approach, platform and tools you're using.
If you're using Buddybuild for CI to build an app and manage environment variables, and you need access to config from JS, create a env.js.example
with keys (with empty string values) for check-in to source control, and use Buddybuild to produce an env.js
file at build time in the post-clone
step, hiding the file contents from the build logs, like so:
#!/usr/bin/env bash
ENVJS_FILE="$BUDDYBUILD_WORKSPACE/env.js"
# Echo what's happening to the build logs
echo Creating environment config file
# Create `env.js` file in project root
touch $ENVJS_FILE
# Write environment config to file, hiding from build logs
tee $ENVJS_FILE > /dev/null <<EOF
module.exports = {
AUTH0_CLIENT_ID: '$AUTH0_CLIENT_ID',
AUTH0_DOMAIN: '$AUTH0_DOMAIN'
}
EOF
Tip: Don't forget to add env.js
to .gitignore
so config and secrets aren't checked into source control accidentally during development.
You can then manage how the file gets written using the Buddybuild variables like BUDDYBUILD_VARIANTS
, for instance, to gain greater control over how your config is produced at build time.