We have a pre build check on our PR's as a requirement to be completed.
We also have a CD release pipeline setup to release the app once new artifacts are published.
The problem is that once the pre release build is run, it publoshes artifacts and releases them.
Is there a way to restrict the publishing only when the code is merged and built?
Try adding the following condition clause to your publish step(s):
condition: and(succeeded(), ne(variables['build.reason'], 'PullRequest'))
This causes the step to be triggered if the previous step succeeded AND the reason for the build is not a pull request.