2009-02-23 91 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()方法。

希望给你一个开始 - 对不起,这不是一个更完整的答案。