Created
September 4, 2013 05:12
-
-
Save piers7/6432985 to your computer and use it in GitHub Desktop.
Load TeamCity system properties into PowerShell variable scope
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
<# | |
.Synopsis | |
Loads TeamCity system build properties into the current scope | |
Unless forced, doesn't do anything if not running under TeamCity | |
#> | |
param( | |
$prefix = 'TeamCity.', | |
$file = $env:TEAMCITY_BUILD_PROPERTIES_FILE + ".xml", | |
[switch] $inTeamCity = (![String]::IsNullOrEmpty($env:TEAMCITY_VERSION)) | |
) | |
if($inTeamCity){ | |
Write-Host "Loading TeamCity properties from $file" | |
$file = (Resolve-Path $file).Path; | |
$buildPropertiesXml = New-Object System.Xml.XmlDocument | |
$buildPropertiesXml.XmlResolver = $null; # force the DTD not to be tested | |
$buildPropertiesXml.Load($file); | |
$buildProperties = @{}; | |
foreach($entry in $buildPropertiesXml.SelectNodes("//entry")){ | |
$key = $entry.key; | |
$value = $entry.'#text'; | |
$buildProperties[$key] = $value; | |
$key = $prefix + $key; | |
Write-Verbose ("[TeamCity] Set {0}={1}" -f $key,$value); | |
Set-Variable -Name:$key -Value:$value -Scope:1; # variables are loaded into parent scope | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment