How to add an active spring profile from an environment variable?

With default addition profile

You can introduce your own environment variable in the application.properties file, next to the defined profiles using an expression. For instance, if your current file looks like this:

spring.profiles.active=profile1,profile2

with a custom environment variable it will change into:

spring.profiles.active=profile1,profile2,${ADDITIONAL_APP_PROFILES:local}

where ADDITIONAL_APP_PROFILES is the name of the environment variable which you set instead of SPRING_PROFILES_ACTIVE.

The value local is used when the variable is not set on a current environment. In that case, the profile called local will be activated. If you don't set the default value and the environment variable is not present, the whole expression will be used as the name of an active profile.

Without default addition profile

If you like to avoid activating the default profile, you can remove the placeholder value and the comma before the variable expression:

spring.profiles.active=profile1,profile2${ADDITIONAL_APP_PROFILES}

but in that case the variable set on a current environment have to start with a comma:

export ADDITIONAL_APP_PROFILES=,local

The next sentence in the documentation you linked to:

Sometimes it is useful to have profile-specific properties that add to the active profiles rather than replace them. The spring.profiles.include property can be used to unconditionally add active profiles.

So you can launch your application with a command-line parameter:

-Dspring.profiles.include=${SPRING_PROFILES_INCLUDE}