Tuesday, July 14, 2015

Check an environment variable having Spring profiles if a specific Spring profile is activated by a Bash script

When an environment variable having Spring profiles is as follows:

SPRING_PROFILE=test,something-else

you can check if `test` Spring profile is activated by using the following Bash script:

spring_active_profiles=(${SPRING_PROFILE//,/ })

spring_profile_test_activated=false
for spring_active_profile in ${spring_active_profiles[@]}
do
  if [ $spring_active_profile == "test" ]
  then
    spring_profile_test_activated=true
  fi
done

echo $spring_profile_test_activated
if [ "$spring_profile_test_activated" = true ]
then
  echo "Spring profile 'test' is activated."
fi

No comments:

Post a Comment