Skip to content

Instantly share code, notes, and snippets.

@bondarenkod
Created September 1, 2020 20:56
Show Gist options
  • Save bondarenkod/379e63dd890a27acdcb5fc32c3e31860 to your computer and use it in GitHub Desktop.
Save bondarenkod/379e63dd890a27acdcb5fc32c3e31860 to your computer and use it in GitHub Desktop.
power shell script for you OSX to clean VSTS DEVOPS build agents working directories
$AGENTS_ROOT = "/Volumes/DATA/agents";
$AGENTS_NAMES = "name1",
"name2",
"name3";
foreach ($name in $AGENTS_NAMES) {
$path = "$AGENTS_ROOT/$name";
Write-Output("stopping agent: $path");
pushd $path
sh ./svc.sh stop
popd
Write-Output("agent stopped: $path");
}
$hasErrors = $false;
foreach ($name in $AGENTS_NAMES) {
try {
$path = "$AGENTS_ROOT/$name";
$pathFull = "$path/_work/*";
# Write-Host "$path [$pathFull]";
Write-Output("cleaning the agent: $path");
Remove-Item -Path $pathFull -Recurse -Force;
Write-Output("agent cleaned: $path");
}
catch {
$hasErrors = $true;
Write-Error ("unable to remove working directory from the agent: $name");
}
}
if ($hasErrors -eq $false){
Write-Output("starting agents...");
# sudo shutdown -r now
foreach ($name in $AGENTS_NAMES) {
$path = "$AGENTS_ROOT/$name";
Write-Output("starting agent at $path");
pushd $path
sh ./svc.sh start
popd
Write-Output("agent started at $path");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment