I have an NPM command that I am running from PowerShell:
npm install process-migrator -g
process-migrator
This command returns an error when its not configured properly, but I cant seam to pick it up in PowerShell.
[ERROR] [2018-09-25T15:30:30.610Z] Cannot find configuration file 'configuration.json'
[INFORMATION] [2018-09-25T15:30:30.615Z] Generated configuration file as 'configuration.json', please fill in required information and retry.
Is there some way to get the error?
I have tried:
if($?) {
Write-Host "Process-Migrator completed sucessfully." $LASTEXITCODE
} else {
Write-VstsTaskError "Process-Migrator FAILED " $LASTEXITCODE -ErrCode $LASTEXITCODE
}
Process-Migrator completed sucessfully. 1
But $? is returning true and $LASTEXITCODE is a 1.
You will need to capture the output of the application first:
$output = & 'process-migrator.exe' 2>&1
if ($LASTEXITCODE -ne 0)
{
$err = $output.Where{$PSItem -match 'ERROR'}
Write-VstsTaskError "Process-Migrator FAILED: $err" -ErrCode $LASTEXITCODE
}
Note: I made an assumption about the extension to be more granular with the execution
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments