Reputation: 683
Using teamCity 8.0.5. As part of my builds cleanup I would like to automatically remove any build older than the current 5 builds. For eg if my build.number = 12 , try and remove build 6. Unfortunately it seems that you can't cast %build.number%-6.
Using Teamcity how can you perform math on a build parameter?
I have tried %build.number% -1 along with wrapping it in ()
%system.PreviousBuild% = \\server\path\Build%build.number%-6
my actual usage of this a command line post build event:
echo trying to remove directory %system.PreviousBuild%
IF EXIST %system.PreviousBuild% RD %system.PreviousBuild% /Q /S
result:
[09:19:09][Step 6/6] trying to remove director \server\path\Build11-6
-------------------------UPDATE---------------------------
the answer below led me to the following solution:
NOTE: The important part here is to cast the build.number as an integer. using powershell source code build step
Using powershell for the entire command worked for me:
Set-Variable -Name previousBuild -Value (([int]%build.number%)-6).ToString()
Write-Output $previousBuild
Write-Output $env:PreviousBuildPath
Set-Variable -Name path -Value $env:PreviousBuildPath$previousBuild
Write-Output $path
if((Test-Path -path $path))
{
Remove-Item -Recurse -Force $path
}
Upvotes: 0
Views: 590
Reputation: 5418
set /a newBuildNumber=%build.number%-6
Then use %%newBuildNumber%% in your TC build script after the path.
\\server\path\Build%%newBuildNumber%%
Upvotes: 0