I have made a few build settings for various configurations, e.g.
e.g.
I can access them in various files (e.g. the info.plist) like so:
${MYTESTSETTING}
However is it possible to get the value in the command line enviroment? e.g. after a xcodebuild from Jenkins
I have tried
echo ${MYTESTSETTING}
And
echo $MYTESTSETTING
xcodebuild -showBuildSettings
shows all build settings, including the user-defined settings. Example:
$ xcodebuild -configuration Debug -showBuildSettings | grep MYTESTSETTING
MYTESTSETTING = DebugValue
$ xcodebuild -configuration Release -showBuildSettings | grep MYTESTSETTING
MYTESTSETTING = ReleaseValue
To get these variables into the environment of your current shell, you have to parse this output. This can for example be done with a Perl script (or many other scripting languages).
Create a Perl script "exportsettings.pl" with the following contents:
#!/usr/bin/perl
open(FH, "xcodebuild -configuration Release -showBuildSettings|");
while(<FH>) {
if (/\s*(\w+)\s*=\s*(.*)$/) { # Search for <key> = <value>
$key = $1; $value = $2;
print "export $key='$value'\n";
}
}
close(FH);
Now you can run the command
$ eval `perl exportsettings.pl`
from the command line, and (almost) all build settings are in the environment. (There will be some error messages, e.g. "UID: readonly variable").
If you need only your used-defined settings in the environment, you could use a unique prefix (e.g. "MY") and change the line
if (/\s*(\w+)\s*=\s*(.*)$/) { # Search for <key> = <value>
to
if (/\s*(MY\w+)\s*=\s*(.*)$/) { # Search for MY<key> = <value>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With