Skip to content

Instantly share code, notes, and snippets.

@atwayne
Created May 18, 2016 17:34
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save atwayne/6bb9a59e3b5f28b3ca2b027e165bff7b to your computer and use it in GitHub Desktop.
Save atwayne/6bb9a59e3b5f28b3ca2b027e165bff7b to your computer and use it in GitHub Desktop.
A powershell script to trigger TeamCity build via REST API
$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
}
@cnucts
Copy link

cnucts commented Jun 14, 2018

we enter correct login creds but still getting 401 unauthorized .. anything should we set on on teamcity server to accept rest api etc?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment