How to run a custom build from the API

Hi, is it possible to run a build with custom options (like in the custom run dialog) from the API? I only see the addToQueue methods on SBuildType although TC supports doing that from http.

8 comments

Sorry for delay. There is no Open API for custom builds at this time. If you really need it, you can try to do the following:
// obtain BuildPromotion object from the build configuration
BuildPromotionEx promo = ((BuildTypeEx)buildType).createBuildPromotion();
// use setUserBuildParameters() to set custom parameters to build promotion (note you cannot remove parameters, just override them and add new)
promo.setUserBuildParameters(customParams);
// use setCustomArtifactDependencies() if you need to override artifact deps

promo.setBuildComment(user, comment); // this sets comment to the build

// after that you can add promotion to the queue
promo.addToQueue("my custom build");

If you want to build on a specific change, this may not be easy because revisions need to be calculated properly.

0

Hi Pavel,

thanks for the pointer. So far I had found the CustomBuildHelperImpl class which lets you add a build to the queue, which is not documented btw.

0

I am trying to do a similar thing - pass parameters to a build from a custom Build Trigger plugin.

I can't seem to find BuildPromotionEx or BuildTypeEx -- which modules are these imported from?

Many thanks,

Mark

0

Mark,

You will need to add <TeamCity server home>\webapps\ROOT\WEB-INF\lib\server.jar as a library of your plugin project.
BTW, I filed a request to add a way to put builds into the queue into open API.

0

Hi Yeggor,

That's great! I have this working now, so I am very happy :-)

Cheers,

Mark

0

Hi guys,

I'm trying to do something similar, but I also need to mark the build as a 'personal build', any ideas how to do this?

(I'm doing the above solution and it works fine, but I haven't found a way to set it as personal)

Thanks
/Johan

**Update**
Found it, works by doing:
BuildPromotionEx promo = ((BuildTypeEx)bt).createPersonalBuildType(getUser(httpServletRequest)).createBuildPromotion();

0

Hopefully, we'll have a better API in 7.0 version.

0

Please sign in to leave a comment.