在 Xcode Server CI bot 运行中访问构建文件夹(环境变量?)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25127146/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 05:19:44  来源:igfitidea点击:

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

xcodecontinuous-integrationxcode6xcode-bots

提问by satyajit

I need to access the folder that is created dynamically during each bot integration. On one of the run it is something like this -

我需要访问在每次机器人集成期间动态创建的文件夹。在一次运行中,它是这样的 -

/Library/Developer/XcodeServer/Integrations/Caches/a3c682dd0c4d569a3bc84e58eab88a48/DerivedData/Build/Products/Debug-iphonesimulator/my.app

/Library/Developer/XcodeServer/Integrations/Caches/ a3c682dd0c4d569a3bc84e58eab88a48/DerivedData/Build/Products/Debug-iphonesimulator/my.app

I would like to get to this folder in an post trigger, how do I go about it? Based on the wwdc talk it seems like some environment variables like 'XCS_INTEGRATION_RESULT' and XCS_ERROR_COUNT etc.. are being used. Also I can see in logs something like PROJECT_DIR.

我想在帖子触发器中访问此文件夹,我该怎么做?根据 wwdc 谈话,似乎正在使用一些环境变量,如“XCS_INTEGRATION_RESULT”和 XCS_ERROR_COUNT 等。我也可以在日志中看到类似 PROJECT_DIR 的内容。

But I can't access any of these variables from my command line(is it because I am a different user than the bot?) Also where can I find the list of variables created by this CI system?

但是我无法从我的命令行访问这些变量中的任何一个(是不是因为我是与机器人不同的用户?)另外,我在哪里可以找到这个 CI 系统创建的变量列表?

回答by Pappy

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=0
XCS_ANALYZER_WARNING_COUNT=0
XCS_ARCHIVE=/Library/Developer/XcodeServer/Integrations/Integration-76eb5292bd7eff1bfe4160670c2d4576/Archive.xcarchive
XCS_BOT_ID=4f7c7e65532389e2a741d29758466c18
XCS_BOT_NAME='Reader'
XCS_BOT_TINY_ID=00B0A7D
XCS_ERROR_CHANGE=0
XCS_ERROR_COUNT=0
XCS_INTEGRATION_ID=76eb5292bd7eff1bfe4160670c2d4576
XCS_INTEGRATION_NUMBER=15
XCS_INTEGRATION_RESULT=warnings
XCS_INTEGRATION_TINY_ID=FF39BC2
XCS_OUTPUT_DIR=/Library/Developer/XcodeServer/Integrations/Integration-76eb5292bd7eff1bfe4160670c2d4576
XCS_PRODUCT='Reader.ipa'
XCS_SOURCE_DIR=/Library/Developer/XcodeServer/Integrations/Caches/4f7c7e65532389e2a741d29758466c18/Source
XCS_TESTS_CHANGE=0
XCS_TESTS_COUNT=0
XCS_TEST_FAILURE_CHANGE=0
XCS_TEST_FAILURE_COUNT=0
XCS_WARNING_CHANGE=36
XCS_WARNING_COUNT=36

回答by EdGs

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

@Viktor 是正确的,这些变量只存在于它们各自的会话中。@Pappy 给出了这些变量的一个很好的列表。

They can be used in a script like so:

它们可以在脚本中使用,如下所示:

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

回答by Viktor Benei

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

我不熟悉 Xcode Server,但通常 Unix/CI 系统在导出环境变量时只将其导出到当前会话。

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).

如果你想持久地设置一个环境变量,你必须在一个初始化文件中设置它,比如 ~/.bash_profile 或 ~/.bashrc 以便在 shell 会话开始时它总是被设置/加载(例如:当你使用终端登录时 -确切的文件取决于您启动的外壳类型)。

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 persistentinitialiser file rather just exportthe variables. With exportthe variable is accessible from the process which exports it and from the child processes the process starts.

这就是为什么通过环境变量进行通信的系统通常不会将变量写入持久初始化文件,而只是导出变量。使用export变量可以从导出它的进程访问,可以从进程启动的子进程访问

For example in a bash script if you exporta 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.

例如,在 bash 脚本中,如果您导出一个变量,您可以在导出后从 bash 脚本以及从 bash 脚本启动的任何命令/程序中访问它,但是当 bash 脚本完成时,环境将不再可访问。

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.

编辑只是为了澄清一下:您应该能够从由 Xcode Server 运行的后触发脚本访问这些环境变量,但您很可能无法从终端/命令行访问这些环境变量。

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

另外我在哪里可以找到这个 CI 系统创建的变量列表?

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

您可以使用env命令打印所有可用的环境变量。在 bash 脚本中,只需在新行中键入env,如下所示:

#!/bin/bash
env

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:

这将打印所有可用的环境变量(不仅仅是由 Xcode Server 定义的环境变量!) - 如果需要,您可以简单地将其通过管道传输到文件进行检查,如下所示:

#!/bin/bash
env > $HOME/envinspect.txt

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

在此脚本运行后,您只需打开用户主文件夹中的 envinspect.txt 文件即可。