簡體   English   中英

如何在以前的TFS構建中使用PowerShell更新構建質量?

[英]How can I use PowerShell to update build qualities on previous TFS Builds?

我們正在使用TFSDeployer來監聽構建質量更改,並在轉換為“Staging”時部署到我們的臨時環境。

我想讓它繼續並更新當前構建質量為“Staging”的所有其他構建被“拒絕”。

這似乎是需要在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

那么,我該怎么做呢?

首先將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

然后找到構建質量為“Staging”的構建

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

最后,更新這些構建的質量

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

(我還沒有運行這個腳本,但你應該能夠毫無困難地運行它)

我的博客上的更多信息: 在PowerShell中使用Team Foundation對象模型

最后一條建議,如果您從TfsDeployer運行的腳本中更新Build質量,如果您有Staging - > Rejected轉換的映射,最終可能會同時運行2個腳本!

這不是完整的答案,因為我對TFSDeployer或PowerScript都不太了解。 但是,Team Build的.NET API能夠執行此操作。 你想獲得構建的IBuildDetail 獲得這個的最簡單方法是,如果你有BuildUri(它聽起來像你可能),在這種情況下,調用IBuildServer.GetBuild應該可以獲得你感興趣的構建。

IBuildServer還有QueryBuilds方法,您可以調用它們來查找您感興趣的構建,然后在IBuildDetails上設置要更改的Quality屬性,記住在每個上調用Save()方法一。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM