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)?
Since TeamCity 9.0 it is possible to override the dependencies parameters by redefining them in the dependent build:
reverse.dep.<btID>.<property name>
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).
Related
I want to create a one-click release build. I am fine creating multiple build configurations and linking them together or building everything in one build configuration.
Module Dependencies are mentioned below:
Module C depends upon module A and B. Module D depends upon module C.
A > C > D
B > C
There could be instances where nothing has been changed on module A or B. If nothing has been changed in a module, I do not want to build and release them as it was already released in past. This would have been simple if I need to build all the modules every time which is not the case.
Let us consider a scenario that there is a change in module B. In this case, I only want to build module B, C & D (but not A).
Is there a way this could be achieved with build step or parameters or by any other means in Team City?
In the Snapshot Dependencies enable the checkbox
Do not run new build if there is a suitable one
Only use successful builds from suitable ones
I recommend using Artifact Dependencies with Snapshot Dependencies.
Enable the follows settings
Build from the same chain
Do not run new build if there is a suitable one
Only use successful builds from suitable ones
Then the TC will not build some of build chain if no chainges
On our TeamCity build server every project now specifies the deployment repository either using the command line argument -DaltDeploymentRepository or <distributionManagement> in the project's POM file.
However we are planning to move to Nexus 3, and there would be considerable amount of work to make sure that all projects are configured correctly. There is also the fact that the deployment procedure has to be communicated with every developer.
Is it possible to specify the Maven deployment target in settings.xml or other so that unless otherwise specified any project that does a deploy on TeamCity will get deployed to the correct repository?
...in settings.xml...no:
Servers
The repositories for download and deployment are defined by the repositories and distributionManagement elements of the POM.
...or other...yes:
Create a (or, if already existing, use the) parent POM from that all your projects inherit.
I figured out another solution: TeamCity meta-runner. By producing a working build you can extract a meta-runner which is kind of like a build-step macro.
If you first get the deployment working you can extract a meta-runner using Actions->Extract meta-runner... in the TeamCity build configuration.
This shows an editor for the XML that specifies the build-runner. Remove all the non-deployment specific build steps, and you can provide build step parameters in the meta-runner/settings/params block. You will probably need to add pomLocation and the specify %pomLocation% in the build step's <params> block.
Is it possible to run dependency builds depending on trigger rules?
For example We have 'Derived' project that is derived from 'Base' project under one solution.
I need to adjust:
if someone commits changes in "solution/Base...": Run build for Base as well as Derived build configurations
if changes was only in Derived folder: Run "solution/Derived" - disable dependency on Base and build just Derived.
When defining the snapshot dependency at Derived (which depends on Base), check the "Do not run new build if there is a suitable one" checkbox.
I've set up top-level project A in TeamCity.
Project A has one build configuration called A1.
Project B is a subproject of A.
Project B has one build configuration called B1.
In this build configuration, I defined two parameters:
env.param1 = "ABCDE"
env.param2 = %param1%
Then, from project B's build configuration (B1), I extract a meta-runner and attach it to B's parent project A.
But when I then I try to use the meta-runner in project A's build configuration (A1), this build won't run; it complains that env.param1 is not defined.
When I look in the definition of the build step (A1) or meta-runner, I can plainly see that env.param1 is defined within. But on project A's build configuration (A1) parameters page, it lists env.param1 as "".
I thought that a meta-runner more or less encapsulates everything defined within it so it can be used anywhere you attach it. From the docs:
Basically, a meta-runner is a set of build steps from one build
configuration that you can reuse in another; it is an xml definition
containing build steps, requirements and parameters that you can
utilize in xml definitions of other build configurations. TeamCity
allows extracting meta-runners using the web UI.
[Snip]
Upon clicking the Extract button, TeamCity will take definitions of
all build steps and parameters in this build configuration and create
a build runner out of them.
What am I doing wrong?
The metarunner is looking at your env.param1 in project A, which is "". To avoid this, use a metarunner-specific variable within the metarunner, and define that in the metarunner's build step. This way, there won't be any confusion.
If you want to parameterize things automatically, you can set the metarunner-specific variable in the build step to reference project A's %env.param1%.
We have 2 project configurations A and B. B depends on A. A commiter makes a change in project A that causes build failure in downstream project B.
Is there a way in TeamCity to notify the commiter of project A that the B has failed because of his change?
Jenkins/Hudson supports that using upstream-individuals:A as an email address in this particular situation.
I tried to set it up through snapshot dependencies as Danere pointed out and it is working. Since the TC way is different from what you probably tried with Jenkins here is my setup:
I added another project to the chain named C that contains 2 VCS: projectA and projectB and a dummy build step.
Project C is configured to be triggered by any VCS change
Project C has a snapshot dependency on project B
Project B has a snapshot dependency on project A
Both project A and B do not have any triggers.
The project C could be probably eliminated but my configuration is more complex and the last step performs system tests and I didn't want it to monitor all VCSs of all the upstream projects.