I'm trying to set up a chocolatey extension module for in-house deployments that does some common housekeeping tasks for our apps. Part of that housekeeping is backing up the existing app install via robocopy in chocolateybeforemodify. The problem is that robocopy doesn't use 0 to mean success so then chocolatey fails because the $lastexitcode is != 0.
I'm tempted to just do this in my function, $global:LASTEXITCODE = $null, but I know it isn't recommended. Is there a better way? I don't want to have my calling code return a different exit code based on current $lastexitcode because then my calling code is making assumptions about how I am doing the backup in this module.
Here is my function, in case it makes any difference.
I'm tempted to just do this in my function, $global:LASTEXITCODE = $null, but I know it isn't recommended. Is there a better way? I don't want to have my calling code return a different exit code based on current $lastexitcode because then my calling code is making assumptions about how I am doing the backup in this module.
Here is my function, in case it makes any difference.
Code:
function Backup-App([string] $appPath, [string] $appsRoot, [string] $appName){
# if the directory doesn't exist, then just return
if(!(Test-Path $appPath)){ return }
# back up the app
Write-Host "Backing up ${appPath}"
$installDate = $(get-date -f yyyyMMdd.HHmm)
$backupRoot = "${appsRoot}\..\backups"
$backupPath = "${backupRoot}\${appName}-${installDate}"
$logPath = "${backupRoot}\${appName}-backup-$installDate.log"
if(!(Test-Path "${backupRoot}")){
New-Item -ItemType Directory -Path "${backupRoot}"
}
robocopy ${appPath} "${backupPath}" /MIR /LOG:"${logPath}"
}