Build fails but deployment stage

We are using Gitlab CI for Deployments , We have build fail with Below error

ERROR in src/app/modules/wayh/pages/back-specific-area.component.html(9,86): : Property ‘toggle’ is private and only accessible within class ‘BackSpecificAreaComponent’.
src/app/modules/wayh/pages/stages/back-specific-area/back-specific-area.component.html(12,16): : Property ‘toggle’ is private and only accessible within class ‘BackSpecificAreaComponent’.

Even Though Build failed It went to next step deployment and It deployed Which caused error on server.
Expected Result:
It should show pipeline failed and Skip the deployment If build fails.

I assume the error occurs on your script. If you want the job to be marked as failed, the script must exit with non-0 code (e.g. 1).

Please try to put exit 1 at the case you want to make the job failed.