Injecting variables from shell to UI test runtime

Hey there,
I am currently struggling with this problem.
When running UI tests for my iOS application I want to acquire an authentication token from an API first, in order to be directly authenticated while the tests run. For using that API I need a client secret, which, because it's a secret, needs to be kept in a secure storage. I can't have that client secret be just somewhere plain text in code or any other unsecured file (xcconfig, plist, ...). That's why I want to put that client secret into macOS' key chain. I also already found out how to access that secret from command line in a build phase script (like security find-generic-password -l ClientSecret -g).
What I also know is how to use launch arguments or environment during UI testing (like ProcessInfo().environment["clientSecret"]).
But I can't seem to find a way to make the connection between an environment variable that I set in a build phase or run pre-action script like
Code Block
export CLIENTSECRET=$(security find-generic-password -l ClientSecret -w)

I tried using that environment variable like clientSecret=$(CLIENTSECRET) in scheme's launch arguments or environment variables, but that doesn't work for me.
Is it even possible to access the bash runtime env variables from within the scheme's arguments? Is there some other way?
Or is there alternatively a chance for me to access the macOS system keychain from the UI test Swift code?

Anyone having an idea? Please help!
Did you ever get this to work? I have same requirement to do now.

Same issue for me! I want to get the git commit and git branch from the Xcode environment (my Macbook) using a Pre-action script for "Test" and then pipe that through to the UI tests so that within the Swift XCUITest code I can call ProcessInfo.processInfo.environment["GIT_BRANCH"]. I know that the git commit and branch env variables are populated correctly inside the script. Then I tried using export and also launchctl setenv in an attempt to export the values to Xcode's environment so that the chaining into the XCUITest code would work, but it does not. Variables I set in the shell prior to launching Xcode do get piped through. But the ones set in the pre-action script are not getting through. :(

Injecting variables from shell to UI test runtime
 
 
Q