2015-10-16 28 views
5

Stavo cercando di creare un meta-runner per generare un file di metadati usando PowerShell in TeamCity e mi chiedevo se ci fosse un modo per scorrere sui vari percorsi vcs?TeamCity - iterating vcs root con PowerShell

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 

Quando aggiungo un'altra radice, i nomi delle radici finiscono per diventare gli identificatori, il che rende difficile per scorrere su di loro dal momento che io non so tecnicamente i nomi del radici.

Ecco un caso d'uso Esempio: ho due VCS radici:

%build.vcs.number.Proj_App_TcTestFW% 
%build.vcs.number.Proj_App_TcTestApp% 

Idealmente, mi piacerebbe per scorrere attraverso di loro in questo modo:

$vcsArray = @() 
foreach ($vcsRoot in vcsRoots) 
{ 
    [email protected]{ 
     "VCSName"= $vcsRoot; 
     "VCSNumber"= "%build.vcs.number." + $vcsRoot% 
    } 

    $vcsArray += $vcsObject 
} 

Ma sembra che io devo codificare i nomi nel mio script, quindi sono attualmente in perdita.

TeamCity espone le rotte VCS in modo tale da consentirne l'iterazione?

Grazie Alex

risposta

1

Ok, non ho un'esperienza TeamCity reale, ma sembra che si può ottenere un elenco di radici mediante l'emissione di un comando di REST:

Invoke-WebRequest -Uri 'http://teamcity.hps.com/httpAuth/app/rest/vcs-roots' -Method Get 

che deve restituire una risposta XML con una lista di radici:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?> 
<vcs-roots count="1"> 
    <vcs-root id="TestProject1_TestProject1perforce" 
       name="test-project1-perforce" 
       href="/httpAuth/app/rest/vcs-roots/id:TestProject1_TestProject1perforce"/> 
</vcs-roots> 

È questo che stai cercando?

Riferimenti:

Problemi correlati