如何解决创建一个复合的Powershell对象
我需要创建一个如下所示的powershell对象:
release
windows
test1 {testName;passRate}
test2 {testName;passRate}
test3 {testName;passRate}
.
.
Linux
test1 {testName;passRate}
test2 {testName;passRate}
test3 {testName;passRate}
.
.
Trunk
windows
test1 {testName;passRate}
test2 {testName;passRate}
test3 {testName;passRate}
.
.
Linux
test1 {testName;passRate}
test2 {testName;passRate}
test3 {testName;passRate}
.
.
“发布,主干,Windows和Linux”是静态的。测试是动态的,这意味着我将添加测试。
有人知道如何解决这个问题吗?
解决方法
你在追求这样的东西吗?
$WinReleaseTest1 = @{
Name = 'WinTest1'
PassRate = 34
}
$WinReleaseTest2 = @{
Name = 'WinTest2'
PassRate = 56
}
$LinuxReleaseTest1 = @{
Name = 'LinuxTest1'
PassRate = 12
}
$LinuxReleaseTest2 = @{
Name = 'LinuxTest2'
PassRate = 75
}
$WinTrunkTest1 = @{
Name = 'WinTest1'
PassRate = 75
}
$WinTrunkTest2 = @{
Name = 'WinTest2'
PassRate = 6
}
$LinuxTrunkTest1 = @{
Name = 'LinuxTest1'
PassRate = 64
}
$LinuxTrunkTest2 = @{
Name = 'LinuxTest2'
PassRate = 32
}
$AllWinReleaseTests = Get-Variable -Name WinReleaseTest* -ValueOnly
$AllLinuxReleaseTests = Get-Variable -Name LinuxReleaseTest* -ValueOnly
$AllWinTrunkTests = Get-Variable -Name WinTrunkTest* -ValueOnly
$AllLinuxTrunkTests = Get-Variable -Name LinuxTrunkTest* -ValueOnly
$TestSummary = [PSCustomObject]@{
Release = @{
Windows = @{
}
Linux = @{
}
}
Trunk = @{
Windows = @{
}
Linux = @{
}
}
}
foreach ($Test in $AllLinuxReleaseTests) {
$TestSummary.Release.Linux.Add($Test.Name,$Test.PassRate)
}
foreach ($Test in $AllWinReleaseTests) {
$TestSummary.Release.Windows.Add($Test.Name,$Test.PassRate)
}
foreach ($Test in $AllLinuxTrunkTests) {
$TestSummary.Trunk.Linux.Add($Test.Name,$Test.PassRate)
}
foreach ($Test in $AllWinTrunkTests) {
$TestSummary.Trunk.Windows.Add($Test.Name,$Test.PassRate)
}
$TestSummary | ConvertTo-Json
输出:
{
"Release": {
"Windows": {
"WinTest2": 56,"WinTest1": 34
},"Linux": {
"LinuxTest1": 12,"LinuxTest2": 75
}
},"Trunk": {
"Windows": {
"WinTest2": 6,"WinTest1": 75
},"Linux": {
"LinuxTest1": 64,"LinuxTest2": 32
}
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。