Created
May 18, 2016 17:34
-
-
Save atwayne/6bb9a59e3b5f28b3ca2b027e165bff7b to your computer and use it in GitHub Desktop.
A powershell script to trigger TeamCity build via REST API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$user = "username" | |
$password = "password" | |
$teamCityHost = "http://teamcity:8082/" | |
$pair = "$($user):$($password)" | |
$encodedCreds = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($pair)) | |
$basicAuthValue = "Basic $encodedCreds" | |
$headers = @{ | |
"Authorization" = $basicAuthValue; | |
"Accept" = "application/xml"; | |
"Content-Type" = "application/xml"; | |
} | |
$buildId = "JavaScriptUnitTestPoc_Build" | |
$body = "<build><buildType id=""$buildId""/></build>" | |
$api = "$($teamCityHost)httpAuth/app/rest/buildQueue" | |
$response = Invoke-WebRequest -Uri $api -Headers $headers -Method POST -Body $body | |
if(200 -ne $response.StatusCode){ | |
exit 1 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
we enter correct login creds but still getting 401 unauthorized .. anything should we set on on teamcity server to accept rest api etc?