Build Runner - Get current build type ID

Hi,

I'm new to TeamCity plugin development, so please excuse me if this is a silly question:

I'm developing a custom build runner, and I need to get a list of VCS tags for the current build type that the build step will be added to. How do I do this? I know I can use getAllBuildTypes() or findBuildTypeById() via ProjectManager, but I need to know the ID of the current build type. I can't see anything in the API for doing this (or maybe I'm blind).

Cheers,
Justin

6 comments
Comment actions Permalink

Hi Justin,

Do you mean you need to find current BuildType in a build runner jsp?

If so, you can use ${buildForm.settingsBuildType} to get the buildType.


If not, please detail what is the context and what specifically you need to access.

BTW, I am not sure that you can get "list of VCS tags" via TeamCity API...

Could you share what is the purpose of the plugin you are developing? Do you plan to make it public for other TeamCity users?

0
Comment actions Permalink

Hi Yegor,

Thanks for replying. Let me explain a little.

I want to build a plugin to compare the binary compatibility of a build artifact (C++ shared libs) with a previous tagged build. So, when the user adds my build step in the GUI, they will be able to select from a drop-down box of previous tags (e.g. v1.0.1). This selected tag will then be passed to the agent, who will acquire the build artifacts from the tagged build, built its own artifacts, then compare the binary signatures of the two artifact sets (using an external program).

I want to pass the list of tags to the GUI in my custom RunType, using RunType.getDefaultRunnerProperties(). If I can get the build type ID, I can use ProjectManager.findBuildTypeById() to return the current SBuildType, and then use SBuildType.getTags() to populate the map returned by RunType.getDefaultRunnerProperties().

If I'm going about this in the wrong way, I would be grateful for any advice! I'm not hugely experienced with the tools involved with writing this plugin, but I want to do it right. And I do plan to make this plugin public eventually, yes.

Cheers,
Justin

0
Comment actions Permalink

Justin,

Thank you for the explanation.

I'd suggest to retrieve the tags from within the run parameters editing JSP: Just iterate through ${buildForm.settingsBuildType.tags}
Wouldn't that work?

Note that the buildForm bean is only avaialble when editing build configuration or template.

Unfortunately, for historic reasons there is no easy way to add a bean into the JSP rendering context. See the related feature request. It also has some comments on possible workarounds if my initial suggestion would not work.

getDefaultRunnerProperties will work only with the just created build step and will not help you add the tasgs on each page opening.

0
Comment actions Permalink

Hi Yegor,

Thanks, that works. Out of interest, where does the buildForm bean come from?

It turns out that I need to do something a little more in-depth, however. I now want to have some dependent drop-down boxes on the build runner edit page (and I want them to be available always, not just during the initial build step creation). I want to be able to choose any build type (from the current project) from select box A, which will then make an asynchronous request to the server to get the list of tags for the selected build type, which will be used to populate select box B. What might be the best way to do this?

The build runner plugin documentation mentions briefly that I can get more control on how the page is processed on the server side, by registering my own extension to the runner editing controller: jetbrains.buildServer.controllers.admin.projects.EditRunTypeControllerExtension . Could you explain this a little? I can't see this implemented in any of the bundled plugins. Is this what I need?

I also attempted the approach mentioned in the comment in the feature request. I have registered a controller, and I have included the controller page in the runner JSP. But I can't seem to make an asynchronous request to the controller (via jQuery). It looks like my jQuery gets stripped out of the page somehow. I'm pretty stuck with this at the moment, so I appreciate all of your help.

Cheers,
Justin

0
Comment actions Permalink

Justin,

You will need to create a new controller (not directly related to the runner editing) and perform ajax request to it.
You can use our util (warning: not part of frozen API as we do not have that for JavaScript, but so far quite stable) with the code like:

BS.ajaxRequest(url, {
       parameters: "param1=aaa&param2=bbb",
       onFailure: function() {
       },
       onComplete: function(response) {
         alert(response.responseText);
       }
});

You can get an example for it in server profiling plugin. Thi si not runner page, but the code will not be any different.

You should also be able to use JQuery, just note that we have jQuery loaded in compatibility mode with prototype, so that can get in the way for your code.

Specifically for the build configuration tags request you can use REST API and request to http://teamcity:8111/httpAuth/app/rest/buildTypes/<buildTypeLocator>/buildTags instead of adding your own controller. Content-types "application/xml" and "application/json" are supported for the request.

0
Comment actions Permalink

Thanks Yegor, that's exactly what I wanted.

Very grateful for all your help! I look forward to getting this plugin released.

Cheers,
Justin

0

Please sign in to leave a comment.