Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I have a build chain with two projects: A is the root project, B depends on it. B has two dependencies configured: an artifact and a snapshot dependency. One build configuration for B has an environment variable (parameter) set. However, I also need this parameter set for the root project A.

Is there any way in TeamCity 9 to pass a build configuration parameter from a project to its dependency (in the same build chain)?

like image 229
Matthias Avatar asked Mar 03 '15 00:03

Matthias


People also ask

How do I add parameters to TeamCity?

In the build number pattern or VCS labeling pattern, you can use the %<prefix>. parameter_name% syntax to reference any parameter known by TeamCity: Predefined parameters of a server or build configuration. Custom build parameters added on the Build Configuration Settings | Parameters page.

What is snapshot dependency in TeamCity?

By setting a snapshot dependency of a build (for example, build B) on another build's (build A) sources, you can ensure that build B will start only after build A is run and finished. We call build A a dependency build, whereas build B is a dependent build.

What is build ID in TeamCity?

Last modified: 26 October 2022. An ID is an identifier given to TeamCity entities (projects, build configurations, templates, VCS roots, and so on). Each entity has two identifiers: external ID. Universally Unique ID, or UUID.


2 Answers

Since TeamCity 9.0 it is possible to override the dependencies parameters by redefining them in the dependent build:

reverse.dep.<btID>.<property name>
like image 176
Alina Mishina Avatar answered Oct 13 '22 19:10

Alina Mishina


For TeamCity 8 and below unfortunately the only way parameters can be passed on is in the direction of the build chain - the reverse of what you want - these properties are called 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>

Dependencies properties flow from the root of the tree to its leaves (in the direction of the build chain flow) , but not the other way round, so the properties of A can be accessed in B.

This is clarified in the docs 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.

I've had a similar use case for the reverse flow before as well - the workaround was not pretty - basically instead of triggering the build chain directly we would trigger an independent build (let's call it X) that was only there to hold the build parameters - then modify the build chain to have the root build (A in your case) depend on the last successful build of X and have the build chain trigger on a successful build of X - this should accomplish what you want.

For TeamCity 9 see @Alina's answer (which should be the accepted answer).

like image 5
BrokenGlass Avatar answered Oct 13 '22 19:10

BrokenGlass