Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing environment variables from fastlane to Xcode build phase script

Is it possible (and if so, how) to pass an environment variable from the script that runs fastlane down to an Xcode Run Script Phase?

My end goal is to read the current git branch name in the Run Script Phase. Our CI is ran by Team Foundation Server which does a git checkout of explicit commits, not branches, so the current branch always shows as HEAD.

TFS -> fastlane -> gym -> xcodebuild -> script that needs the branch

It is possible to get the branch that triggered the build only via an environment variable set by TFS. My plan is to get that value down to the Xcode script to do what I need.

I would prefer not to use this as it passes all enviornment variables to the build process, if I understand it correctly.

defaults write com.apple.dt.Xcode UseSanitizedBuildSystemEnvironment -bool NO
like image 951
Jay Whitsitt Avatar asked Apr 24 '19 19:04

Jay Whitsitt


1 Answers

To pass env-variables to BuildPhases use xcargs in Fastfile:

build_app(workspace: ..., scheme: ..., xcargs: "SOMEVAR1='one' SOMEVAR2='two'")

This command generates xcodebuild ... SOMEVAR1='one' SOMEVAR2='two', and then these variables will become available in Build Phases.

like image 118
Pavel Shorokhov Avatar answered Oct 22 '22 20:10

Pavel Shorokhov