(Also reported via Feedback Assistant as FB13683080)
Has there been a known change to the behaviour of environment variables in Xcode build in 15.3? I couldn't find anything documented in the release notes.
We have a shell script which would export some environment variables and then run xcodebuild to build and test a macOS project, something like this (simplified):
#!/usr/bin/env bash
PROJECT=Validator/Validator.xcworkspace
SCHEME=Validator
# In reality, API_KEY's value was sourced from elsewhere, it wasn't directly in the script
API_KEY="xxxxxx"
export API_KEY
xcodebuild -workspace $PROJECT -scheme $SCHEME -sdk macosx build-for-testing
xcodebuild -workspace $PROJECT -scheme $SCHEME test
One of the tests then does:
var apiKey = ProcessInfo.processInfo.environment["API_KEY"]
Up to Xcode 15.2 this worked fine, when upgrading to Xcode 15.3 the environment variable is no longer available to the test.
I've logged the contents of ProcessInfo.processInfo.environment in the test via Xcode 15.2 and 15.3. 15.2 includes all the environment variables set in the shell/script that launched xcodebuild. Under 15.3 the only ones set seem to be Xcode internal ones.
Is this a known change? Is there a way to opt back into the previous behaviour? I don't want to write stuff into the Swift test directly to retrieve the API_KEY as the script will still need it for other reasons so it'll just be duplicating code.
I had a reply to my Feedback Assistant report; only environment variables prefixed with TEST_RUNNER_ will be passed on to tests (with the prefix stripped).
Once I was told this I did a bit more research on TEST_RUNNER_:
- This was mentioned as being added in the Xcode 13.0 release notes: https://developer.apple.com/documentation/xcode-release-notes/xcode-13-release-notes but other environment variables were still being passed through at that time.
- It was added to
xcodebuild's man page in Xcode 14.0 Beta 3: https://github.com/keith/xcode-man-pages/commit/f67a80c54fe446936b30556599bfe009e6545486 - Xcode 15.3 was when it stopped passing through non
TEST_RUNNER_environment variables (though this wasn't mentioned in the release notes).