Creating a build configuration in TeamCity using Powershell
Anyone know how I can create or delete a build configuration in TeamCity, only using Powershell? I am trying to automate our entire project setup process; have looked at the REST API but that appears to be mostly read-only开发者_高级运维.
There is no ability to automate creation of build configuration. Watch/vote for corresponding feature request JetBrains tracker: http://youtrack.jetbrains.net/issue/TW-7999.
Teamcity 8.x REST provides the ability to create build configuration. You can use something like below to utilize to REST API.
function Create-Build{
param
(
[Parameter(Mandatory=$true)]
[string]
$buildName,
[Parameter(Mandatory=$true)]
[string]
$parentProjectId
)
# Create Teamcity URL
$url = "http://teamcity:8111/httpAuth/app/rest/projects/$parentProjectId/buildTypes"
$webRequest = [System.Net.WebRequest]::Create($url)
$webRequest.ContentType = "text/plain"
$PostStr = [System.Text.Encoding]::UTF8.GetBytes($buildName)
$webrequest.ContentLength = $PostStr.Length
$webRequest.Method = "POST"
$webRequest.Accept = "*/*"
$webRequest.Credentials = new-object system.net.networkcredential("teamcityuser", "password")
$requestStream = $webRequest.GetRequestStream()
$requestStream.Write($PostStr, 0,$PostStr.length)
$requestStream.Close()
[System.Net.WebResponse] $resp = $webRequest.GetResponse();
$rs = $resp.GetResponseStream();
[System.IO.StreamReader] $sr = New-Object System.IO.StreamReader -argumentList $rs;
[string] $results = $sr.ReadToEnd();
$results
}
# Call ps function to create build configuration
Create-Build -buildName "CopiedBuild" -parentProjectId "TestProject"
Have you looked at psake? It's a build automation tool and somebody integrated some TeamCity support (in teamcity.ps1).
精彩评论