7

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

1 Answer 1

13

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.

4
  • 3
    The syntax is quoted, so something like this: "BUILD_NUMBER='43' VERSION_NUMBER='12'"
    – trishcode
    Commented Nov 23, 2020 at 23:15
  • 1
    Does boolean values has to be quoted as well? For example when you have: "-allowProvisioningUpdates -UseModernBuildSystem=NO"
    – Skodik.o
    Commented Jun 21, 2021 at 7:06
  • How to i use these inside the build phases scripts?
    – Mr Spring
    Commented Sep 19, 2021 at 13:51
  • @MrSpring like env vars: $SOMEVAR1
    – Gobe
    Commented Jan 15, 2022 at 4:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.