是否有任何 msbuild-task 可以在 TFS Builds (TFS2008) 中的单元中获取可用空间?

发布于 2024-11-18 03:10:54 字数 259 浏览 3 评论 0原文

我的构建失败是因为有时我的构建服务器中没有磁盘空间。问题是错误信息不明确。它在任何随机部分失败,并且发生这种情况时日志不可用。

我正在寻找一项任务来获取单元的可用空间,以便在磁盘空间不足时我可以发出消息......但我找不到任何消息。

是否有任何 msbuild-task 可以在 TFS Builds 中的单元中获取可用空间?

我知道我可以用 C# 开发一个任务并自己完成..但我现在没有时间。

谢谢。

My builds are failing because some times I have no disk-space in my build server. The problem is that the error message is not clear. It fails in any random part and log is not available when this happens.

I was looking for a task to get free space of a unit so I can put a message if disk space is running low... but I can't find any.

Is there any msbuild-task to get free space in a unit in TFS Builds?

I know I can develop a task in C# and do it myself.. but I don't have the time right now.

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

逐鹿 2024-11-25 03:10:54

您可以使用 MSBuild 扩展包 来执行此操作:

<!--- Check drive space -->
<MSBuild.ExtensionPack.Computer.SystemDrive TaskAction="CheckDriveSpace" Drive="DriveLetter:\" MachineName="Name" UserName="UserName" UserPassword="Password" MinSpace="SpaceToTriggerError EX: 500" Unit="Size EX: MB" ContinueOnError="false"/>

<!--- Check drive space on a remote machine -->
<MSBuild.ExtensionPack.Computer.SystemDrive TaskAction="GetDrives"  MachineName="Name" UserName="UserName" UserPassword="Password" />

You can use the MSBuild Extension Pack to do this:

<!--- Check drive space -->
<MSBuild.ExtensionPack.Computer.SystemDrive TaskAction="CheckDriveSpace" Drive="DriveLetter:\" MachineName="Name" UserName="UserName" UserPassword="Password" MinSpace="SpaceToTriggerError EX: 500" Unit="Size EX: MB" ContinueOnError="false"/>

<!--- Check drive space on a remote machine -->
<MSBuild.ExtensionPack.Computer.SystemDrive TaskAction="GetDrives"  MachineName="Name" UserName="UserName" UserPassword="Password" />
风和你 2024-11-25 03:10:54

还有另一种方法。添加一个新目标,它将执行 PowerShell 脚本。此 PowerShell 脚本将检查可用空间。

<Target Name="CheckFreeSpace">
    <PropertyGroup>
        <PowerShellExe Condition=" '$(PowerShellExe)'=='' ">
            %WINDIR%\System32\WindowsPowerShell\v1.0\powershell.exe
        </PowerShellExe>
        <ScriptLocation Condition=" '$(ScriptLocation)'=='' ">
            C:\Build\CheckFreeSpace.ps1
        </ScriptLocation>
    </PropertyGroup>
    <Exec Command="$(PowerShellExe) -NonInteractive -executionpolicy Unrestricted 
                     -command "& invoke-command -scriptblock { 
                              &'$(ScriptLocation)'}
                              ""/>  
</Target>

并创建 powershell 脚本 C:\Build\CheckFreeSpace.ps1

Write-Output "Powershell scrip start."

$disks = Get-CimInstance -ClassName Win32_LogicalDisk

$freeSpace = $disks | Select-Object -Property DeviceID,@{'Name' = 'FreeSpace (MB)'; Expression= { [int]($_.FreeSpace / 1MB) }} -First 1

if($freeSpace.'FreeSpace (MB)' -gt 4000){ # Free space in MB
    Write-Output "There is more then 4000 MB free space."
    Exit 0
} else {
    Write-Output "Not enough free space."
    Exit -1
} 

也可以仅使用一个 liner 命令。但我没有正确测试它:

"& invoke-command -scriptblock { 
      &Get-CimInstance -ClassName Win32_LogicalDisk `
| Select-Object -Property DeviceID,@{'Name' = 'FreeSpace (MB)'; Expression= { [int]($_.FreeSpace / 1MB) }} `
,@{'Name' = 'Enought'; Expression= { [int]($_.FreeSpace / 1MB) -gt 400000 }} -First 1 `
| %{if($_ -match "True"){Exit 0 }else{Exit -1}}}"

There is also another way. Add a new target, which will execute PowerShell script. This PowerShell script will check for free space.

<Target Name="CheckFreeSpace">
    <PropertyGroup>
        <PowerShellExe Condition=" '$(PowerShellExe)'=='' ">
            %WINDIR%\System32\WindowsPowerShell\v1.0\powershell.exe
        </PowerShellExe>
        <ScriptLocation Condition=" '$(ScriptLocation)'=='' ">
            C:\Build\CheckFreeSpace.ps1
        </ScriptLocation>
    </PropertyGroup>
    <Exec Command="$(PowerShellExe) -NonInteractive -executionpolicy Unrestricted 
                     -command "& invoke-command -scriptblock { 
                              &'$(ScriptLocation)'}
                              ""/>  
</Target>

And create powershell script C:\Build\CheckFreeSpace.ps1

Write-Output "Powershell scrip start."

$disks = Get-CimInstance -ClassName Win32_LogicalDisk

$freeSpace = $disks | Select-Object -Property DeviceID,@{'Name' = 'FreeSpace (MB)'; Expression= { [int]($_.FreeSpace / 1MB) }} -First 1

if($freeSpace.'FreeSpace (MB)' -gt 4000){ # Free space in MB
    Write-Output "There is more then 4000 MB free space."
    Exit 0
} else {
    Write-Output "Not enough free space."
    Exit -1
} 

There is possibility also to use just one liner command. But I did not test it properly:

"& invoke-command -scriptblock { 
      &Get-CimInstance -ClassName Win32_LogicalDisk `
| Select-Object -Property DeviceID,@{'Name' = 'FreeSpace (MB)'; Expression= { [int]($_.FreeSpace / 1MB) }} `
,@{'Name' = 'Enought'; Expression= { [int]($_.FreeSpace / 1MB) -gt 400000 }} -First 1 `
| %{if($_ -match "True"){Exit 0 }else{Exit -1}}}"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文