I was trying to create a meta-runner to generate a metadata file using powershell in TeamCity and I was wondering if there was a way to iterate over the different vcs routes?
My Code:
$fileName = "metadata.json"
$vcsArray = @()
for ($i = 0; $i -le 5; $i++)
{
$vcsObject= @{
"VCSNumber"="%build.vcs.number.Proj_App_TcTestApp%"
}
$vcsArray += $vcsObject
}
$content = @{
"TeamCityBuildLogUrl" = "http://teamcity.hps.com/viewLog.html?buildId=%teamcity.build.id%&tab=buildResultsDiv&buildTypeId=%system.teamcity.buildType.id%";
"TeamCityProjectName" = "%system.teamcity.projectName%";
"TeamCityBuildNumber" = "%system.build.number%";
"BuildDateGenerated" = (Get-Date).ToString();
"TeamCityExecutionAgentName" = "%teamcity.agent.name%";
"VCSes" = $vcsArray
}
}
$content = $content | Add-Member @{"VCS Version2" = "testValue"} -PassThru # How to add more members dynamically.
$content = ConvertTo-JSON $content
New-Item $fileName -type file -force -value "// Metadata file generated by TeamCity`n"
Add-Content $fileName $content
cat $fileName # Test afterwards
When I add another root, the names of the roots end up becoming the identifiers, which makes it difficult to iterate over them since I don't technically know the names of the roots.
Here's an example use-case: I have two vcs roots:
%build.vcs.number.Proj_App_TcTestFW%
%build.vcs.number.Proj_App_TcTestApp%
Ideally, I'd like to iterate through them like so:
$vcsArray = @()
foreach ($vcsRoot in vcsRoots)
{
$vcsObject=@{
"VCSName"= $vcsRoot;
"VCSNumber"= "%build.vcs.number." + $vcsRoot%
}
$vcsArray += $vcsObject
}
But it seems that I have to hardcode the names in my script, so I'm currently at a loss.
Does TeamCity expose the VCS routes in such a way that I can iterate over them?
Thanks Alex