0

I am using TeamCity 9.x.

I have to create 400 sub-projects under a main project. Is there a way to automate these project creations?

Note: every sub-project has an unique VCS URL.

ANIL
  • 2,542
  • 4
  • 25
  • 44

2 Answers2

1

TeamCity REST API is well suited for doing stuff like this.

To create new project you can send POST request containing XML description of the new project using curl:

curl -v -u USER:PASSWORD http://teamcity:8111/app/rest/projects --header "Content-Type: application/xml" --data-binary
"<newProjectDescription name='New Project Name' id='newProjectId'><parentProject locator='id:project1'/></newProjectDescription>"

where USER and PASSWORD are the credentials of a valid TeamCity user, teamcity:8111 is the TeamCity server URL.

Alternatively, JSON might be used. "Content-Type: application/json" header should be provided and request body could be something like

{
  "name":"New Project Name",
  "id":"newProjectId0000",
  "parentProject": {
    "locator":"id:FooProject"
  }
}

To create a new VCS root you shoul POST VCS root XML or JSON (the one like retrieved for a GET request for VCS root details) to http://teamcity:8111/httpAuth/app/rest/vcs-roots. An example XML:

<vcs-root id="vcsRoot_id_whatever" name="auto-generated-1" vcsName="jetbrains.git">
<project id="FooProject"/>
<properties count="10">
<property name="agentCleanFilesPolicy" value="ALL_UNTRACKED"/>
<property name="agentCleanPolicy" value="ON_BRANCH_CHANGE"/>
<property name="branch" value="refs/heads/master"/>
<property name="teamcity:branchSpec" value="+:*"/>
<property name="url" value="https://github.com/JetBrains/teamcity-docker-agent.git"/>
<property name="usernameStyle" value="USERID"/>
</properties>
</vcs-root>
cyberskunk
  • 1,722
  • 20
  • 22
1

The old variant was to use TeamCity REST Api. But now jetbrains introduced the new Kotlin DSL.

You set up your project settings to use Vcs settings with type Kotlin.

Then you just use your programming skills to create a code that creates all your projects from Kotlin dsl.

More information in docs: https://confluence.jetbrains.com/display/TCD10/Kotlin+DSL

Alexander.Iljushkin
  • 4,519
  • 7
  • 29
  • 46