TeamCity. How to trigger some actions on change of certain repo? - continuous-integration

I'm using TeamCity 9.1.7
We have 3 git repos, and they all need to create build.
But, I need to run extra tests if certain of these 3 repos has changes.
I'm using command line in build steps like:
if [%env.VAR% == 'foo']
then
action 1
action 2
fi
Is there any variable which can tell me that only certain of my repos was changed? Or is there any other ways to detect that?

You should set up one more build configuration with spearate triggering rules. Use "copy" build configuration action on project settings page.

Related

One build-agent for several repo

I have 2 configurations in the teamcity which refer to 2 separate repositories in the mercurial. When starting a build the project updates all its files. Can we configure 1 build agent to have 2 reprositories so that only the changes of the corresponding project are taken and not all files of the project at updated when starting the configuration? Or do we need to create 2 agents?
If TeamCity decided to clean checkout directory on an agent, it should log why this happens into the build log of the build.
Possible reasons of clean checkout are outlined in documentation: https://confluence.jetbrains.com/display/TCD18/Clean+Checkout

Pass/share parameter values between dependant builds in TeamCity

Setup: Build CD has has Artifact Dependency and Snapshot Dependency on Build CI. Build CI pulls from VCS root and generates artifacts for Build CD.
Problem: In Build CD I need %teamcity.build.branch% parameter, but it's not available, because it only uses artifacts and has no VCS Roots linked.
Question: Is there a way to pass parameters between dependant builds? (search results in the googles seem of topic)
Workaround 1: I can access %teamcity.build.branch% in Build CD if I link it to same VCS root Build CI is using, but I'd like to avoid having this link and Build CD unnecessarily pulling from VCS (build log shows it does this).
Workaround 2: I could write parameter to a file in Build CI and read from it in Build CD later. This is a hack and I would like to avoid it as well.
Absolutely. In CD, add a parameter called whatever, with value equal to %dep.Build_CI.teamcity.build.branch%. TeamCity will help you figure out the exact value thanks to its auto-suggestion/auto-completion, once you type %dep..

setup trigger for file change in teamcity

I can setup teamcity trigger to run tests whenever there in VCS checkin/ change.
Then I setup command line build steps to access files on system .
e.g. `custom script'
cd ~/Desktop
ls
But is there way to trigger test run if there is change in file e.g. test.txt
I want to setup trigger as 'if file changes run tests'.
Or it has to be git checkin?
You would add a new "VCS Trigger" under your project configuration and you would add a new "Trigger rules" specifying the file/directory that should trigger the build. For example: +:root=ContecIT:ContecRepairSystem/** (here I am saying monitor the VCS root "ContecIT", and watch for any files changes under the "ContecRepairSystem" directory.
I'm not aware of any "FileSystemWatcher" feature in TC for triggering builds, unfortunately. Sounds like a good idea for a new TC plugin.
I've checked (here) if perhaps there's such a plugin already. Seems not. The "Url Build Trigger" comes closest. You could try to fork and adjust it to suit your needs.
I think your use case is quite rare. Usually a TC farm comprises many TC agents, each running on a different machine. Thus, they can't monitor the same filesystem (e.g. the Desktop directory), except perhaps some shared folders...
VCS trigger configuration would monitor for any git checkin and triggers the build process

How to prevent build steps running for personal builds

We have a build configuration in TeamCity with 3 build steps. Is there a way to prevent step 2 from running for personal builds such that normal VCS triggers executes steps 1, 2 and 3 - but only 1 and 3 are run for personal builds?
There is a variable BUILD_IS_PERSONAL set to true for personal builds, but it isn't defined if not:
http://confluence.jetbrains.com/display/TCD8/Predefined+Build+Parameters
How are you meant to use the variable as whenever I use it in a build configuration script, it asks me to define the value manually?
BUILD_IS_PERSONAL is a usual environment variable. It is only set if build is personal. Your build step can check for presence of this variable and exit immediately if it is defined.
For unix shell something like this should work:
if [ -n "$BUILD_IS_PERSONAL" ]; then
echo "Build is personal, exiting"
exit 0
fi
You could clone your build configuration (you could leverage templates, if your build configuration is not yet based on a template), and have two build configurations: one for normal builds and another for personal builds. On the personal build configuration, you would disable step 2.
I modified the configuration for the second step to be wrapped in this if statement:
IF "%%BUILD_IS_PERSONAL%%"=="" (
rem do stuff
)
The thing I had been missing was escaping the TeamCity variable syntax with an extra '%'.

Triggering post build and passing in branch name from successful build

I've used Google and looked at the Docs but can't find an answer.
I want to trigger another build or a rake script to do some cleaning up of files after a successful build. I currently use Rake to do my build and pass in %teamcity.build.branch% to it.
I would like to know if I can pass the same branch name of the successful build to the triggered build or script. I can then use this to do some tidying up.
Thanks
In addition to finished build trigger, you need to add snapshot dependency, with "Run build on the same agent" option enabled. This way, cleanup will run after each build, on the same agent.
You then will be able to refer to original build's branch name using dependencies parameters:
%dep.<original_bt_id>.teamcity.build.branch%

Resources