2009-02-23 73 views
3

我們正在使用TFSDeployer來偵聽構建質量變化,並在轉換到「分段」時將其部署到我們的分段環境中。如何使用PowerShell更新以前的TFS構建版本的構建質量?

我想繼續前進,並更新當前構建質量爲「暫存」的所有其他構建爲「已拒絕」。

這似乎是一些需要PowerShell腳本,它看起來像內部發生:

$droplocation = $TfsDeployerBuildData.DropLocation 
ECHO $droplocation 

$websourcepath = $droplocation + "\Release\_PublishedWebsites\CS.Public.WebApplication\" 
$webdestinationpath = "\\vmwebstg\WebRoot\CreditSolutions\" 

new-item -force -path $webdestinationpath -itemtype "directory" 
get-childitem $webdestinationpath | remove-item -force -recurse 
get-childitem $websourcepath | copy-item -force -recurse -destination $webdestinationpath 

$configFile = $webdestinationpath + "web.development.config" 
remove-item $configFile -force 

$configFile = $webdestinationpath + "web.staging.config" 
$configFileDest = $webdestinationpath + "web.config" 
move-item $configFile $configFileDest -force 

那麼,我該怎麼辦呢?

+0

你試過了嗎? – Kiquenet 2015-05-05 06:31:23

回答

3

首先添加GET-TFS功能腳本:

function get-tfs (
    [string] $serverName = $(Throw 'serverName is required') 
) 
{ 
    # load the required dll 
    [void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.Client") 

    $propertiesToAdd = (
     ('VCS', 'Microsoft.TeamFoundation.VersionControl.Client', 'Microsoft.TeamFoundation.VersionControl.Client.VersionControlServer'), 
     ('WIT', 'Microsoft.TeamFoundation.WorkItemTracking.Client', 'Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore'), 
     ('BS', 'Microsoft.TeamFoundation.Build.Common', 'Microsoft.TeamFoundation.Build.Proxy.BuildStore'), 
     ('CSS', 'Microsoft.TeamFoundation', 'Microsoft.TeamFoundation.Server.ICommonStructureService'), 
     ('GSS', 'Microsoft.TeamFoundation', 'Microsoft.TeamFoundation.Server.IGroupSecurityService') 
    ) 

    # fetch the TFS instance, but add some useful properties to make life easier 
    # Make sure to "promote" it to a psobject now to make later modification easier 
    [psobject] $tfs = [Microsoft.TeamFoundation.Client.TeamFoundationServerFactory]::GetServer($serverName) 
    foreach ($entry in $propertiesToAdd) { 
     $scriptBlock = ' 
      [System.Reflection.Assembly]::LoadWithPartialName("{0}") > $null 
      $this.GetService([{1}]) 
     ' -f $entry[1],$entry[2] 
     $tfs | add-member scriptproperty $entry[0] $ExecutionContext.InvokeCommand.NewScriptBlock($scriptBlock) 
    } 
    return $tfs 
} 

接下來,實例化TFS對象

$tfs = get-tfs http://YourTfsServer:8080 

然後找到該版本與 「轉移」

的建設質量
$builds = $tfs.BS.GetListOfBuilds("Test Project", "TestBuild") | 
where {$_.BuildQuality -eq "Staging"} 

最後,更新這些版本的質量

foreach ($build in $builds) { $tfs.BS.UpdateBuildQuality($build.BuildUri, "Rejected") } 

(我沒有運行此腳本,但你應該能夠得到它去無煩惱)在我的博客

更多信息:Using the Team Foundation Object Model with PowerShell

最後一個建議是,如果你更新從TfsDeployer運行的腳本中創建質量,如果您有分段映射 - >拒絕轉換,則最終可以同時運行2個腳本!

+0

在排除當前構建的where子句中是否應該存在某種類型的限定符?換句話說,TfsDeployer掌握之前或之後的當前版本是否設置了暫存質量? – NotMe 2009-03-03 15:22:23

1

這不是完整的答案,因爲我對TFSDeployer或PowerScript沒有多少了解。然而,Team Build的.NET API能夠做到這一點。你想獲得構建的IBuildDetail。得到這個最簡單的方法是,如果你有BuildUri(這聽起來像你可能)在這種情況下,以IBuildServer.GetBuild一個電話應該讓你構建你感興趣的內容。

IBuildServer也有QueryBuilds方法,你會可以調用以查找您感興趣的構建,然後您可以在要更改的IBuildDetails上設置Quality屬性,並記住在每個構造上調用Save()方法。

希望給你一個開始 - 對不起,這不是一個更完整的答案。