Dynamic App Env

I am using Bitrise cli to test my workflows locally.
I would like to set an app environment variable based on the fact that I am using the cli or the bitrise server

Eg.

---
....
app:
  env:
    - SOMEVAR: {{if .IsCI}}some_ci_vaue{{else}}some_local_value{{end}}
...

Is it possible?

1 Like

Might be possible that way with Go Templates too, but in general the easier solution for this is to set the env var in your .bitrise.secrets.yml and check in your script whether it’s set (if required).

E.g.

#!/bin/bash
set -ex

if [[ "${SOMEVAR}" == "yes" ]] ; then ...

# OR

if [[ ! -z "${SOMEVAR}" ]] ; then ...

Or, if you have to set it to a specific value, you can use a Script step to set it:

#!/bin/bash
set -ex

if [[ -z "${CI}" ]] ; then
  # not CI env
  envman add --key SOMEVAR --value "some local value"
fi

(http://devcenter.bitrise.io/tips-and-tricks/expose-environment-variable/)