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

时间:2009-02-23 20:12:39

标签: tfs powershell build

我们正在使用TFSDeployer收听构建质量更改,并在转换为“暂存”时部署到我们的暂存环境。

我想让它继续并更新当前构建质量为“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

那么,我该怎么做呢?

2 个答案:

答案 0 :(得分: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

然后找到构建质量为“Staging”的构建

$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运行的脚本中更新Build质量,如果您有Staging的映射,那么最终可能会同时运行2个脚本 - >拒绝过渡!

答案 1 :(得分:1)

这不是完整的答案,因为我对TFSDeployer或PowerScript都不太了解。但是,Team Build的.NET API能够执行此操作。您希望获得构建的IBuildDetail。获得此功能的最简单方法是,如果您拥有BuildUri(听起来像你可能),在这种情况下,调用IBuildServer.GetBuild可以获得您感兴趣的构建。

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

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