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

标签 tfs powershell build

我们使用 TFSDeployer 来监听构建质量的变化,并在过渡到“暂存”时部署到我们的暂存环境。

我想让它继续进行,并将当前构建质量为“暂存”的所有其他构建更新为“已拒绝”。

这似乎是需要在 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") }

(我还没有运行这个脚本,但你应该能够顺利运行它)

更多信息在我的博客上:Using the Team Foundation Object Model with PowerShell

最后一个建议,如果您从 TfsDeployer 运行的脚本中更新构建质量,如果您有暂存的映射 --> 拒绝转换,您最终可能会同时运行 2 个脚本!

关于tfs - 如何使用 PowerShell 更新以前 TFS 构建的构建质量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/579132/

相关文章:

TFS:在指定版本不存在

TFS 构建保持 'in progress' 状态,而不会以错误或成功完成构建 [TFS 2012]

powershell - Powershell Invoke-WebRequest返回 “remote name could not be resolved”,但不返回代理错误

powershell - PSExec Pass参数带有Powershell空格

java - Maven的pom.xml中的pluginManagement是什么?

build - 使用 Rust Cargo 进行构建的不同目标名称

visual-studio - TFS 构建通知未显示任何项目

visual-studio-2013 - "Access to the path is denied."尝试将文件检入到 TFS 时

azure - Newb Powershell 问题创建自适应范围以实现合规性

java - Gradle 构建失败