使用Powershell在TeamCity中创建构建配置

时间:2010-08-16 15:54:34

标签: powershell teamcity

任何人都知道如何在TeamCity中创建或删除构建配置,只使用Powershell?我正在尝试自动化整个项目设置过程;看过REST API但看起来主要是只读的。

3 个答案:

答案 0 :(得分:2)

无法自动创建构建配置。观看/投票相应的功能请求JetBrains跟踪器:http://youtrack.jetbrains.net/issue/TW-7999

答案 1 :(得分:1)

Teamcity 8.x REST提供了创建构建配置的功能。您可以使用类似下面的内容来使用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"

答案 2 :(得分:0)

你看过psake了吗?它是一个构建自动化工具,有人整合了一些TeamCity支持(在teamcity.ps1中)。