Skip to content

Instantly share code, notes, and snippets.

@software-programmer
Last active January 13, 2021 13:52
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save software-programmer/a75a98dfff1a08d670b6d1fd402e51a5 to your computer and use it in GitHub Desktop.
Save software-programmer/a75a98dfff1a08d670b6d1fd402e51a5 to your computer and use it in GitHub Desktop.
This script can be used inside TeamCity to get the build status of a build configuration and write the value back out to a parameter. http://evsoftware.co.uk
# Set Build Configuration Id
$BuildTypeId = "BuildConfiguration_Name"
# Create Credentials using built in user / password
$ApiCredentials = New-Object System.Management.Automation.PSCredential("%system.teamcity.auth.userId%", (ConvertTo-SecureString "%system.teamcity.auth.password%" -AsPlainText -Force))
# Invoke and get status
$status = Invoke-RestMethod -Credential $ApiCredentials -Uri "%teamcity.serverUrl%/httpAuth/app/rest/builds/buildType:$BuildTypeId/status" -Method GET;
# Set to an output parameter
Write-Host "##teamcity[setParameter name='BuildConfiguration_Name_Status' value='$status']"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment