代码之家  ›  专栏  ›  技术社区  ›  ChrisLively

如何使用PowerShell更新以前的TFS生成的生成质量?

  •  3
  • ChrisLively  · 技术社区  · 16 年前

    我们使用tfsdeployer来监听构建质量更改,并在过渡到“staging”时将其部署到临时环境中。

    我想让它继续运行,并更新当前构建质量为“staging”的所有其他构建,以“rejected”。

    这似乎是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
    

    那么,我该怎么做呢?

    2 回复  |  直到 16 年前
        1
  •  3
  •   thijs    16 年前

    首先将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个脚本结束!

        2
  •  1
  •   Martin Woodward    16 年前

    这不是完整的答案,因为我对tfsDeployer或Powerscript没有太多了解。然而,用于团队构建的.NET API能够做到这一点。你想抓住 IBuildDetail 用于构建。最简单的方法是,如果您有buildUri(听起来可能是这样),在这种情况下,调用 IBuildServer.GetBuild 你应该得到你感兴趣的建筑。

    IBuildServer还具有 QueryBuilds 方法,您可以调用这些方法来查找您感兴趣的构建,然后在要更改的IBuildDetails上设置Quality属性,记住对每个方法调用save()方法。

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