PowerShell Tips

Maven and PowerShell on GitHub Actions: Exit Codes

The IBM FHIR Server open source project builds on Windows and Linux using GitHub Actions. The GitHub Actions code uses a step which calls build/pre-integration-test.ps1 which calls out to maven in the workflow.

The call out to maven in tests.ps1. Originally the code called mvn which returns no $ExitCode, and never fails the workflow on a maven failed build.

To properly call out to maven and get the ExitCode and fail it, I create a process in PowerShell, and exit when not equal 0.

$PROC = Start-Process -FilePath "mvn.cmd" -ArgumentList "-B test -DskipTests=false -f .\fhir-server-test\pom.xml -DskipWebSocketTest=true --no-transfer-progress" -PassThru -Wait
if($PROC.ExitCode -ne 0){
  Write-Host "Exiting with Error Condition"
  [Environment]::Exit(1)
}

I hope this helps others.