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.
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>