How to tell publish task not to publish to a repo if artifact already there?

I am adding publish tasks to publish artifacts to corporate maven repository. What is the right way to tell my scripts that this should not be done if the specified artifact already exists in this repository? I don’t want errors in my script because of this. I want to check before publishing.