Create projects and build types programatically



Hi,

I am wondering if it's possible to create build types programatically? I have been looking around the API and I see there are two server-side classes:
- jetbrains.buildServer.serverSide.ProjectManager
- jetbrains.buildServer.serverSide.SProject
I am not quite sure how to get a hold of them in order to be able to create projects. Could somebody give me an example, or point me to an existing plugin's code where something like this is done?

Many thanks in advance,

Martin

3 comments
Comment actions Permalink

Hi Martin,

You can get ProjectManager via Spring autowiring and then proceed from there.
For an example, see createProject method in REST API inplementation.

0
Comment actions Permalink

Thanks Yegor,

I managed to create a project by just posting with the following options:

final URL url = new URL("http://" + host + ":" + port + "/admin/createProject.html?" +
                                "-ufd-teamcity-ui-parentId=" + URLEncoder.encode("<Root project>", "UTF-8") +"&" +
                                "externalId=" + URLEncoder.encode(projectId, "UTF-8") + "&" +
                                "name=" + URLEncoder.encode(name, "UTF-8") + "&" +
                                "description=" + URLEncoder.encode(description, "UTF-8") + "&" +
                                "parentId=_Root&" +
                                "submitCreateProject=Create" +
                                "submitProject=store");



For the time-being, I might not have to use the server-side classes, but rather -- just invoke the command from the client side.
0
Comment actions Permalink

You seem to emulate the request as sent form the browser. That is a valid approach, but quite fragile speaking of TeamCity version upgrades.
I'd rather recommend to use REST API approach.

0

Please sign in to leave a comment.