I found out the hard way that mvn (Maven) on Windows always return a success code of true, which means you cannot use the return code ($?) to check whether the mvn command succeeded or failed. Why they decided to break this seemingly basic program contract is a mystery. A work-around is to scan the mvn output and look for specific strings such as “BUILD SUCCESSFUL”.
Here’s how:
function InvokeAndCheckStdOut($cmd, $successString, $failString) {
Write-Host "====> InvokeAndCheckStdOut"
$fullCmd = "$cmd|Tee-Object -variable result"
Invoke-Expression $fullCmd
$found = $false
$success = $false
foreach ($line in $result) {
if ($line -match $failString) {
$found = $true
$success = $false
break
}
else {
if ($line -match $successString) {
$found = $true
$success = $true
#"[InvokeAndCheckStdOut] FOUND MATCH: $line"
break
}
else {
#"[InvokeAndCheckStdOut] $line"
}
}
}
if (! $success) {
PlayWav "${env:windir}\Media\ding.wav"
throw "Mvn command failed."
}
Write-Host "InvokeAndCheckStdOut <===="
}
function InvokeMvn($cmd) {
InvokeAndCheckStdOut $cmd "BUILD SUCCESSFUL" "BUILD FAILED"
}
InvokeMvn "mvn clean install"
To list available contexts: kubectl config get-contexts To show the current context: kubectl config current-context…
kubectl exec -it <podname> -- sh To get a list of running pods in the…
# Create a soft symbolic link from /mnt/original (file or folder) to ~/link ln -s…
git config --global user.name "<your name>" git config --global user.email "<youremail@somewhere.com>" Related Commands Show current…
TypeScript/JavaScript function getLastMonday(d: Date) { let d1 = new Date(d.getFullYear(), d.getMonth() + 1, 0); let…
I had to do some SMTP relay troubleshooting and it wasn't obvious how to view…
View Comments