将环境变量(参数)传递给 TeamCity 中的依赖项目

Passing an environment variable (parameter) to dependency project in TeamCity

我有一个包含两个项目的构建链:A 是根项目,B 依赖于它。 B 配置了两个依赖项:工件和快照依赖项。 B 的一个构建配置有一个环境变量(参数)集。但是,我还需要为根项目 A 设置此参数。

TeamCity 9 中是否有任何方法可以将构建配置参数从项目传递到其依赖项(在同一构建链中)?

不幸的是,对于 TeamCity 8 及以下版本,唯一可以传递参数的方法是在构建链的方向上——与您想要的相反——这些属性称为 Dependencies Properties:

Dependencies Properties

These are properties provided by the builds the current build depends on (via a snapshot or an artifact dependency).

Dependencies properties have the following format:

dep.<btID>.<property name>

依赖属性从树的根流向它的叶子(在构建链流的方向),但不是相反,因此可以在 B 中访问 A 的属性。

文档中对此进行了说明 here:

Parameters in dependent builds

TeamCity provides the ability to use properties provided by the builds the current build depends on (via a snapshot or artifact dependency). When build A depends on build B, you can pass properties from build B to build A, i.e. properties can be passed only in the direction of the build chain flow and not vice versa. For the details on how to use parameters of the previous build in chain, refer to the Dependencies Properties page.

我之前也有一个类似的反向流用例 - 解决方法不是很好 - 基本上我们不会直接触发构建链,而是触发一个独立的构建(我们称之为 X),它只是在那里保存构建参数 - 然后修改构建链以使根构建(在你的情况下为 A)取决于 X 的最后一次成功构建并让构建链触发 X 的成功构建 - 这应该完成你想要的.

对于 TeamCity 9,请参阅@Alina 的回答(这应该是公认的答案)。

从 TeamCity 9.0 开始,可以 override the dependencies parameters 通过在依赖构建中重新定义它们:

reverse.dep.<btID>.<property name>