I am running batch script using octopus rus a script step to deploy the sql DBs using dacpac and I am calling this script from powershell since we dont have option to run batch script directly in this step.
I created a for loop to deploy the dacpac on all required DBs and if any DB fails it will terminate the script, please find the below syntax.
for /f “delims=” %%x in (alldb.txt) do (
“SqlPackage.exe” /Action:Publish /SourceFile:“dacpac” /TargetDatabaseName:"%%x" /TargetServerName:“DB” /TargetUser:“user” /TargetPassword:“password” || echo ERROR && exit /b
so when ever deployment failed for any DB this script is going to stop and when I run echo %errolevel% giving 1, but the same script when I run from powershell this step is showing as successful and octopus email is triggering success email, please find the attached screenshots.
So I ran the same script in powershell directly and then ran echo $? and it returned true, thats why octopus step showing as successful, so how can I make step success or failure depending on this batch script return value.
Please find the screenshot .