Custom Trigger with Branch Support

Hello,

I love the new branch support in the latest version of TeamCity.  Unfortunately though, I've noticed that there currently is no way to build or update triggers (other than the commit trigger) to kick off a build for multiple branches.

I'm considering writing a custom trigger plugin to handle this, but before I dive too deep into trying to put this together as a custom plugin, I'm wondering if anyone can tell me if my goal is even attainable.  I have seen other posts that allude to being able to kick off a build with custom parameters.  So, I think this part may be attainable assuming I can pass it the branch name.  However, does anyone know if there is even a way to specify the branch name via api for the custom build and whether or not I would be able to get the available branches, or, if they would have to be configuration parameters for my trigger?

Any thoughts are appreciated...

ray

1 comment
Comment actions Permalink

Hi Ray,

I've experimented with a trigger for gerrit, it listens for gerrit events and trigger builds in TeamCity when new gerrit change appears. I'm going to publish a code once it's ready.

To implement a trigger you need to extend class BuildTriggerService and return a subclass of PolledBuildTrigger from its getBuildTriggeringPolicy() method. A heart of the trigger is PolledBuildTrigger.triggerBuild() method. TeamCity calls it periodically and a trigger gets a chance to run a build.

A branch-related API is not a part of an open-api yet and can be changed in a future. To work with branches you have to cast SBuildType to BuildTypeEx. To get active branches call BuildTypeEx.getActiveBranches() and to create a build on a branch use the following sequence:

BuildPromotionEx p = buildType.createBuildPromotion(branchName);
p.setCustomParameters(params); //if you need them
p.addToQueue("Name of your trigger");

Hope it helps.

0

Please sign in to leave a comment.