1

I have a run script in my Xcode project's Build Phases. I want to make it run only on machines where a custom environment variable is set.

In my ~/.bash_profile file I have

export MY_VARIABLE="TRUE"

There is an appropriate check in the Xcode's run script:

if [ "$MY_VARIABLE" != "TRUE" ]; then
    exit
fi

I tested this code in Terminal, and it works well, but Xcode's run script does not see $MY_VARIABLE.

Does anybody know how to make it visible in the run script?

I tried the approach recommended in this answer but it does not work for me: XCode doesn't recognize environment variables

Thank you!

Rostyslav Druzhchenko
  • 3,673
  • 3
  • 33
  • 38
  • Apps don't see the environment variables you set in your profile. See [this question](https://superuser.com/questions/476752/setting-environment-variables-in-os-x-for-gui-applications) on SuperUser. – trojanfoe Aug 28 '19 at 14:30
  • Why don't you set a custom userdefined setting? It will be only for your account and your machine. – Mojtaba Hosseini Aug 28 '19 at 15:10

1 Answers1

3

Try add source ~/.bash_profile to begin of your run script.

Thanh Vu
  • 1,599
  • 10
  • 14
  • Thank you @Thanh Vu, it works! I did it previously in my Terminal and restarted Xcode thinking that it should work. Passing it right to the script made it work. – Rostyslav Druzhchenko Aug 28 '19 at 19:55