Skip to content

Instantly share code, notes, and snippets.

@yetanotherchris
Last active October 31, 2021 23:31
Show Gist options
  • Save yetanotherchris/d83391afba959b27dbcd to your computer and use it in GitHub Desktop.
Save yetanotherchris/d83391afba959b27dbcd to your computer and use it in GitHub Desktop.
Trigger another Teamcity build as a build step (because Teamcity triggers lose the triggeredBy environmental variable)
# Trigger the acceptance tests
# Docs: https://confluence.jetbrains.com/display/TCD8/REST+API#RESTAPI-TriggeringaBuild
$branchName = "%teamcity.build.branch%"
$url = "http://teamcity.mydomain.com:8500/guestAuth/app/rest/buildQueue"
$buildId = "%system.teamcity.buildType.id%"
$buildId = $buildId.Replace("_Deploy", "_AcceptanceTests")
$webClient = New-Object net.webclient
try {
$xml = "<build branchName=`"$branchName`"><buildType id=`"$buildId`"/></build>"
Write-host "Sending this xml to $url : $xml"
$webClient.Headers.Add("Content-Type", "application/xml")
$webClient.UploadString($url, $xml) | write-host "ok"
}
catch {
Write-Host "Looks like this project doesn't have acceptance tests, ignoring."
exit 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment