I’m trying to implement a CI pipeline to do some basic kustomize validation using PowerShell.
Essentially if I run kustomize build . and it produces an error, catch it with a try catch or simply throw an error.
It doesn’t seem that PowerShell detects it as an error or anything I can store into a variable to read off of. Has anyone attempted this before? Any ideas?
I would just use powershell as below code and see it it works.
try {
# Run kustomize and redirect both stderr and stdout
kustomize build . 2>&1 | Out-Null
# Check the exit code
if ($LASTEXITCODE -ne 0) {
throw "Kustomize build failed with exit code $LASTEXITCODE"
}
Write-Host "Kustomize build succeeded."
} catch {
Write-Error "Error during kustomize build: $_"
exit 1
}
Hi Jayesh,
That looks like it works - thanks!
Zach
1 Like