TeamCity Rest API POST XML : argument type mismatch

Hi Guys,

I am running "TeamCity Professional 9.1.4 (build 37293)"

I'm looking into automating the setup of our TeamCity instance and trying to figure out why I'm getting "argument type mismatch" errors when trying to create a project from the rest api by posting XML.

I can create a project named MyProject like this :

curl -u admin:admin -X POST -d 'MyProject' -H 'Content-Type: text/plain' http://192.168.99.100:8111/httpAuth/app/rest/projects/

I can then save the MyProject xml to file :

curl -O -u admin:admin -X GET http://192.168.99.100:8111/httpAuth/app/rest/projects/MyProject

which gives me a file named MyProject with this content :

<?xml version="1.0" encoding="UTF-8" standalone="yes"?><project id="MyProject" name="MyProject" parentProjectId="_Root" href="/httpAuth/app/rest/projects/id:MyProject" webUrl="http://192.168.99.100:8111/project.html?projectId=MyProject"><parentProject id="_Root" name="&lt;Root project&gt;" description="Contains all other projects" href="/httpAuth/app/rest/projects/id:_Root" webUrl="http://192.168.99.100:8111/project.html?projectId=_Root"/><buildTypes count="0"/><templates count="0"/><parameters count="0" href="/app/rest/projects/id:MyProject/parameters"/><vcsRoots href="/httpAuth/app/rest/vcs-roots?locator=project:(id:MyProject)"/><projects count="0"/></project>

If I then delete MyProject from TeamCity and then try to recreate it by posting the XML :

curl -u admin:admin -H "Content-Type: application/xml" -d @MyProject -X POST http://192.168.99.100:8111/httpAuth/app/rest/projects/

I get the error :

Error has occurred during request processing (Bad Request).
Error: java.lang.IllegalArgumentException: java.lang.ClassCastException@cf5e507
Most probably the URL requires submitting different data type. Please check the request URL and data are correct.

Can somebody help me out with what I'm doing wrong here?

I have been able to succesfully post XML like this to create a VCS root with :

curl -u admin:admin -H "Content-Type: application/xml" -d @MyProject_MyVCS -X POST http://192.168.99.100:8000/httpAuth/app/rest/vcs-roots/

@MyProject_MyVCS content is :

<?xml version="1.0" encoding="UTF-8" standalone="yes"?><vcs-root id="MyProject_MyVCS" name="MyVCS" vcsName="jetbrains.git" status="NOT_MONITORED" lastChecked="20151209T041306+0000" href="/httpAuth/app/rest/vcs-roots/id:MyProject_MyVCS"><project id="MyProject" name="MyProject" parentProjectId="_Root" href="/httpAuth/app/rest/projects/id:MyProject" webUrl="http://192.168.99.100:8000/project.html?projectId=MyProject"/><properties count="9"><property name="agentCleanFilesPolicy" value="ALL_UNTRACKED"/><property name="agentCleanPolicy" value="ON_BRANCH_CHANGE"/><property name="authMethod" value="ANONYMOUS"/><property name="branch" value="refs/heads/master"/><property name="ignoreKnownHosts" value="true"/><property name="submoduleCheckout" value="CHECKOUT"/><property name="url" value="https://www.git.com/myproject"/><property name="useAlternates" value="true"/><property name="usernameStyle" value="USERID"/></properties><vcsRootInstances href="/httpAuth/app/rest/vcs-root-instances?locator=vcsRoot:(id:MyProject_MyVCS)"/></vcs-root>

So I don't know why this doesn't work for Projects.

Regards Alex

2 comments

Hello Alex,

Currently it's not possible to create project using XML retrieved for GET request. Please use the following format: https://confluence.jetbrains.com/display/TCD9/REST+API#RESTAPI-exampleNewProjectCurl.
I created a feature request to support this case: https://youtrack.jetbrains.com/issue/TW-43542. Please vote.

0

Thanks Alina,

In the mean time I'm going to mount the projects config xml into the docker container like so :

docker run -v $PWD/BuildServer/config/projects:/root/.BuildServer/config/projects --net=host teamcity:9.1.1

So I can persist my TeamCity build configs and also have them checked into source control.

Regards Alex

0

Please sign in to leave a comment.