Being able to browse/add/update/remove projects and build configurations via HTTP/REST programatically.
Current workarounds:
- write TeamCity Java/Groovy/JRuby plugin with full access to object mode via openAPI, expose required API from the plugin
- generate necessary XMLs under .BuildServer/config caring about correct structure and unique IDs. See also some related notes in a comment
- (for adding new projects and build configurations) create a "template" project or build configuration and then copy it from en external tool emulating user's copy action from the web browser, in line with the notes.
--- original issue text:
e.g. we could then write a script to look for project
http://myserver/builds/someProjectif it didn't exist we could POST a blob of XML (or JSON - don't care, whatever you prefer) to this URL to create a new project (or PUT to update its settings).
Then we can find the builds for each project again via HTTP/REST and add/remove builds that way.
This would then make it easy for folks to manage the various builds and their configurations using any language/technology.
Some background: We're hosting a ton of projects; we use a Rails application to create them and their resources (JIRA, wik, git repos and so forth). It would be great if we could just do a few HTTP GET/POSTs to setup projects in TeamCity - we could then some well defined templates of builds (e.g. a nightly, checkin and deploy build for each project - the only thing that changes for each project is typically its name and its VCS location)
Can you detail why do you need to do automated changes to the configurations (probably with use cases)?
Can you list the operations that you need most to do remotely?
Thank you for details. It seems that for now you can try to create a project with default settings that you would copy to create a new one.
Most probably you can copy the project now from an external script using "undocumented" way like the one described on the page. The actual URL and parameters can be looked up from the actual request browser sends to the server when you copy a project in UI.
However, since this is an undocumented way, it can be changed in any of the future TeamCity versions without any prior notice.
Lots of room to expand, of course, but it's a start. It's derived from the samplePlugin.zip in the devPackage that ships with TeamCity, and tested against 6.0.3.
https://github.com/walquis/teamcity-plugin-vcsrootmanager
Cheers,
This is currently possible. No locks are exposed to the open API and so far it's not clear why we would need to do that. Can you describe why do you need the lock? It can be better to move this discussion into the forum as it seems to be a bit off the main issue.
Provided the changes are not made simultaneously, that should not be the case. If you can reproduce this, it can be investigated separately.
Basically, changing xml is about the same as changing the settings from web UI: if there is a concurrent change, the last change wins.
Oh, I see you've created a thread on this: http://devnet.jetbrains.net/message/5304150#5304150
Let's continue there.
That this isn't available is a real bummer. An API that would provide our automation scripts a means to create new projects and build configurations, as well as manipulate existing ones, is practically essential for my organization's needs. If this were available in the TeamCity product, I'd select it over CCNet right this minute. Unfortunately, since it is not in the product, the decision has become pained.
This request was made 2 years ago; is it seriously being considered for addition to the REST API?
http://devnet.jetbrains.net/thread/430524
I've added some build configuration editing functionality into the current TeamCity trunk (7.0).
What is available now:
What is NOT available:
nothing about build configuration template (no editing, not even viewing)UPDATE: this is already available in EAP, build 21075VCS root editingUPDATE: this will be available since build 21138 (not yet public)TeamCity 7.0 release is planned very soon, within 6-8 weeks, so any early feedback on new REST API features is highly appreciated. If you do care about the functionality, please try it and let us know about any issues or thoughts. Posts to the forum and links here are welcome.
I am attaching current version of REST API plugin: rest-api_TW-8394_1.zip.It should be compatible with the last TeamCity EAP, build 20939.You can use the plugin in the latest EAP by copying the attached zip under .BuildServer\pluginsUPDATE: just use EAP build 21075
A tiny example of a step viewing and new creation:
curl -v --request GET http://user:pass@localhost:8111/app/rest/buildTypes/id:bt2/steps
curl -v --request GET http://user:pass@localhost:8111/app/rest/buildTypes/id:bt2/steps/RUNNER_1 -o response.xml
curl -v --request POST http://user:pass@localhost:8111/app/rest/buildTypes/id:bt2/steps --data-binary @response.xml --header "Content-Type: application/xml"
Build configuration copying:
curl -v --request POST http://user:pass@localhost:8111/app/rest/projects/id:project10/buildTypes --data "<newBuildTypeDescription name='Conf Name' sourceBuildTypeLocator='id:bt42' copyAllAssociatedSettings='true' shareVCSRoots='false'/>" --header "Content-Type: application/xml"
All the supported requests are listed in response to /app/rest/application.wadl request. You are also welcome to see not-so-pretty source code, if interested.
I can also think of the following useful features:
And it would be great to have a bit more documentation too =)
Available via: curl -v --request PUT http://user:pass@localhost:8111/app/rest/buildTypes/id:bt2/name --data "New name"
Available in the above-described manner via:
curl http://user:pass@localhost:8111/app/rest/buildTypes/id:bt778/vcs-root-entries
curl -v --request GET http://user:pass@localhost:8111/app/rest/buildTypes/id:bt778/vcs-root-entries/id:3 -o response.xml
curl -v --request DELETE http://user:pass@localhost:8111/app/rest/buildTypes/id:bt2/vcs-root-entries/id:3
curl -v --request POST http://user:pass@localhost:8111/app/rest/buildTypes/id:bt2/vcs-root-entries --data-binary @response.xml --header "Content-Type: application/xml"
I would appreciate details on what needs the explanation most.
http://user:pass@localhost:8111/app/rest/application.wadl should list all the available requests. XML schema for the used entities will also be available in the next EAP.
UPDATED (to match recent TeamCity EAP)
My workflow:
1) curl -v –request GET http://user:pass@localhost:8111/app/rest/vcs-roots/id:1 -o response.xml
2) change name and id in response.xml
3) curl -v –request POST http://user:pass@localhost:8111/app/rest/buildTypes/id:bt2/vcs-roots –data-binary @response.xml –header "Content-Type: application/xml"
What wrong?
Also, I think
curl -v –request GET http://user:pass@localhost:8111/app/rest/buildTypes/id:bt778/vcs-roots/id:3 -o response.xml
should work like
curl -v –request GET http://user:pass@localhost:8111/app/rest/vcs-roots/id:3 -o response.xml
not like just cropped version of
curl -v –request GET http://user:pass@localhost:8111/app/rest/buildTypes/id:bt778/vcs-roots -o response.xml
If you use attached version of the plugin with the latest TeamCity EAP, I'd appreciate a separate issue on this not to pollute this one.
Please describe what does "don't work for me" mean exactly - what is the output, what is in teamcity-rest.log, etc.
Your suggestion about buildTypes/XX/vcs-roots/YY vs vcs-roots/YY is probably another issue. However, as the entities returned are different, so far I could not agree.
http://youtrack.jetbrains.net/issue/TW-19802?projectKey=TW
Second comment is just my opinion, feel free to ignore it.
The schema should also be available, see <grammars> tag at the beginning of application.wadl
e.g. try http://localhost:8111/httpAuth/app/rest/application.wadl/xsd1.xsd
You are supposed to POST the same XML that you get on GET for an existing VCS root. The logic as for all other entities. I've updated the doc a bit on this.
Yes, that's how it works, search for "Attach VCS root to a build configuration" on the REST doc page.
http://localhost:8111/httpAuth/app/rest/vcs-roots/id:2/properties/user
I vcs root 2 is a valid vcs root. I am doing a GET request. As per the documentation (GET/PUT http://teamcity:8111/httpAuth/app/rest/vcs-roots/<vcsRootLocator>/properties/<property_name>) I would expect this to return the value for the 'user' property for the vcs root. I am receiving:
Error has occurred during request processing (Not Found).
Error: com.sun.jersey.api.NotFoundException: null for uri: http://localhost:8111/app/rest/vcs-roots/id:2/properties/user
Please check URL is correct.
Thank you for trying new additions to REST API. Could you please post a new issue or create a new forum thread so that we do not keep updating this issue?
Please include the build number that you are using and output of http://localhost:8111/app/rest/vcs-roots/id:2/properties request.
Thanks,
Jay
In 7.0 you can PUT "false" to http://localhost:8111/app/rest/buildTypes/id:bt10/paused to pause a build configuration.
Also, in 7.0 in web UI you can move all the projects that you are not interested about in a separate agent pool with no agents.
Or make the connected agents compatible only with specific configurations on "Compatible Configurations" Agent tab.
Please post additional questions to the forum.
Triggering a build is not yet available via REST (TW-14941), but it can be done by doing the same request as user in web UI, see the documentation: http://confluence.jetbrains.net/display/TCD65/Accessing+Server+by+HTTP
BTW, please do not post generic questions here. The forum is a good place to ask questions, however.