Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does one use Xcode Bot Environment Variables?

When setting up a bot there's an "Environment" tab that looks like this:

env

I would expect to be able to access this Environment variable in my test like this:

NSString *username = [[NSProcessInfo processInfo] environment][@"accountEmail"];

But that comes back as nil. And I can verify that [NSProcessInfo processInfo] is populated with other data by logging its contents to the console.

I think this is a pretty new Bot feature (neither the 2015 WWDC videos nor Apple's documentation even mention this tab), but has anybody had success accessing these bot environment variables?

like image 534
Adam Kaump Avatar asked Apr 01 '26 09:04

Adam Kaump


2 Answers

In order to access an environment variable set through a bot's "Arguments" tab, you must first account for that variable in your scheme.

In Xcode 9.2, go to Edit scheme... > Run > Arguments > Environment Variables and add your environment variable with Name accountEmail and Value $(accountEmail). Then the value you set for the environment variable in your bot's configuration should be accessible in code through (in Swift 4) ProcessInfo.processInfo.environment["accountEmail"].

like image 181
sizzle beam Avatar answered Apr 04 '26 13:04

sizzle beam


I'm noticing the same thing. Seems like a bug in Xcode Server. You should probably log a Radar.

In the meantime, you can add environment variables to schemes. You can make several schemes for different configurations and switch which one your Bot uses. It's not ideal, but it gets the job done.

Build Scheme Run Settings

like image 26
Mark Avatar answered Apr 04 '26 12:04

Mark



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!