gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 13:08:58 24 4
gpt4 key购买 nike

我们使用 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com