I'm trying to attach a build configuration to a template. We're running TeamCity 10.0.2, using PowerShell 4.0 to interact with it.
According to the TeamCity 10 API documentation, the attachment of builds to templates operation is possible:
Read, detach and attach a build configuration from/to a template: GET/DELETE/PUT http://teamcity:8111/app/rest/buildTypes//template (PUT accepts template locator with the "text/plain" Content-Type)
So I'm trying to attach the build12
build configuration to the template12
template, the code I'm doing this with is as follows
$webclient = New-Object System.Net.WebClient
$creds = New-Object System.Net.NetworkCredential("user1","pass1")
$webclient.Credentials = $creds
$webclient.headers.Add("Content-Type", "text/plain")
$webclient.UploadString("http://teamcity:8111/httpAuth/app/rest/buildTypes/build12/template", "PUT", "TemplateId")
But I keep getting the following error back:
Exception calling "UploadString" with "3" argument(s): "The remote server returned an error: (400) Bad Request."
Has anyone been able to attach build configurations to templates through the API?
I see you using PowerShell, but you're dropping down the the C#
WebClient
class to do it. Don't do that :)This will attach the template
Your_Template
to your build calledYourBuildId
If you need help with the
-Credentials
param or anything else, let me know.I've actually got it to work using the above...