Skip to content

Instantly share code, notes, and snippets.

@Sam-Martin
Created July 4, 2017 09:48
Show Gist options
  • Save Sam-Martin/f3aebae8a1ed625a92b309ac0e828a06 to your computer and use it in GitHub Desktop.
Save Sam-Martin/f3aebae8a1ed625a92b309ac0e828a06 to your computer and use it in GitHub Desktop.
Clean up Jenkins Build history
$BuildDirs = gci "W:\Jenkins\jobs\" -recurse -filter builds | ?{$_.psiscontainer}
$BuildDirs | %{
$Builds = $_ | gci | select *,@{L="NameInt";e={[int]$_.name}} | ?{$_.nameint}| sort nameint -Descending
if($builds.Length -gt 30){
$Builds[30..$($builds.length-1)].fullname | Remove-Item -Force -Recurse -verbose
}else{
$Builds.Length
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment