Access build folder in Xcode Server CI bot run (env variables?) Access build folder in Xcode Server CI bot run (env variables?) xcode xcode

Access build folder in Xcode Server CI bot run (env variables?)


I have been echoing set to the bot log, the first line of my bot script is simply

set   

When you view the log after the integration is complete it will be in your trigger output.

XCS_ANALYZER_WARNING_CHANGE=0XCS_ANALYZER_WARNING_COUNT=0XCS_ARCHIVE=/Library/Developer/XcodeServer/Integrations/Integration-76eb5292bd7eff1bfe4160670c2d4576/Archive.xcarchiveXCS_BOT_ID=4f7c7e65532389e2a741d29758466c18XCS_BOT_NAME='Reader'XCS_BOT_TINY_ID=00B0A7DXCS_ERROR_CHANGE=0XCS_ERROR_COUNT=0XCS_INTEGRATION_ID=76eb5292bd7eff1bfe4160670c2d4576XCS_INTEGRATION_NUMBER=15XCS_INTEGRATION_RESULT=warningsXCS_INTEGRATION_TINY_ID=FF39BC2XCS_OUTPUT_DIR=/Library/Developer/XcodeServer/Integrations/Integration-76eb5292bd7eff1bfe4160670c2d4576XCS_PRODUCT='Reader.ipa'XCS_SOURCE_DIR=/Library/Developer/XcodeServer/Integrations/Caches/4f7c7e65532389e2a741d29758466c18/SourceXCS_TESTS_CHANGE=0XCS_TESTS_COUNT=0XCS_TEST_FAILURE_CHANGE=0XCS_TEST_FAILURE_COUNT=0XCS_WARNING_CHANGE=36XCS_WARNING_COUNT=36


@Viktor is correct, these variables only exist during their respective sessions. @Pappy gave a great list of those variables.

They can be used in a script like so:

IPA_PATH="${XCS_OUTPUT_DIR}/${XCS_BOT_NAME}.ipa"echo $IPA_PATH


I'm not familiar with Xcode Server but generally Unix/CI systems when export environment variables they only export it to the current session.

If you want to set an environment variable persistently you have to set it in an initializer file like ~/.bash_profile or ~/.bashrc so it always gets set/loaded when a shell session starts (ex: when you log in with Terminal - the exact file depends on what kind of shell you start).

It wouldn't make much sense to export these persistently either, because in that case if you run different integrations these would simply overwrite each others exported environment variables (they would set the same environment variables).

That's why the systems which communicate through environment variables usually don't write the variables into persistent initialiser file rather just export the variables. With export the variable is accessible from the process which exports it and from the child processes the process starts.

For example in a bash script if you export a variable you can access it from the bash script after the export and from any command/program you start from the bash script, but when the bash script finishes the environment won't be accessible anymore.

editJust to clarify it a bit: You should be able to access these environment variables from a post trigger script, run by Xcode Server but you most likely won't be able to access these from your Terminal/command line.

Also where can I find the list of variables created by this CI system?

You can print all the available environment variables with the env command. In a bash script simply type env in a new line like this:

#!/bin/bashenv

This will print all the available environment variables (not just the ones defined by Xcode Server!) - you can simply pipe it to a file for inspection if you want to, like this:

#!/bin/bashenv > $HOME/envinspect.txt

After this script runs you can simply open the envinspect.txt file in the user's home folder.