Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to trigger expensive build steps only when required?

Tags:

teamcity

I have a TeamCity project with the following build configurations:

  1. Gather dependencies (expensive)
  2. Build
  3. Test
  4. Deploy

Say I know whether I need to do it by changes to some file deps.txt.

Here's what I want to do:

  • I want to trigger builds on all changes in version control.
  • If deps.txt has changed, I want to run builds 1, then 2, then 3, then 4.
  • If deps.txt has not changed, I want to run builds 2 then 3 then 4.

I tried putting triggers on build configurations like this:

  1. VCS trigger on no checkins, unless +:deps.txt
  2. VCS tigger on all checkins, unless -:deps.txt
  3. Snapshot dependency on 2, trigger when 2 finishes building
  4. Snapshot dependency on 3, trigger when 3 finishes building

but if a commit includes changes deps.txt and other files, then configurations 1 and 2 trigger at the same time, meaning that configuration 2 will fail.

Is there an easy way to do this in TeamCity?

like image 885
Timothy Jones Avatar asked Aug 31 '17 01:08

Timothy Jones


2 Answers

I would like to suggest a different approach:

a. Creating duplicate build configuration

b. Triggering the whole build chain from the last build.

The first chain of Build Configurations:

  1. Gather dependencies: no trigger

  2. Build: snapshot and artifact dependency on 1 on the same build chain, no trigger

  3. Test: snapshot and artifact dependency on 2 on the same build chain, no trigger

  4. Deploy: snapshot and artifact dependency on 3 on the same chain, VCS trigger on +:deps.txt

The second chain of Build Configurations:

  1. Build: snapshot and artifact dependency on 1 on Last successful build, no trigger

  2. Test: snapshot and artifact dependency on 5 on the same chain, no trigger

  3. Deploy: snapshot and artifact dependency on 6 on the same chain, VCS trigger on any change -:deps.txt

In order to reduce duplicates you may use templates for 2 and 5, 3 and 6, 4 and 7.

like image 81
Boris Modylevsky Avatar answered Nov 16 '22 01:11

Boris Modylevsky


You could combine 1 into 2, and then for the build step of 1 which gathers dependencies, write a custom script which uses the teamcity.build.changedFiles.file property (see TeamCity docs) to check if deps.txt has actually changed or not, and then either gather dependencies or not. The rest of the build steps from 2 would then proceed as normal.

like image 2
gezzahead Avatar answered Nov 16 '22 03:11

gezzahead