Authentification is required for some remote command : push, clone, pull.
For these commands, you can add the <auth> nested element.
The mercurial keyring extension allow to automate scripts without prompting the password.

Auth nested element

Attribute Description Value Required
mode auth mode auth*|keyring no, auth by default (user + password)
user user login yes
password user password for auth mode

<hg cmd="push" destination="">
  <auth user="ant4hg" password="******" />

Mercurial keyring

Mercurial_keyring extension save user passwords and avoid them to prompt password in automated ant scripts.
Installation and configuration
see: mercurial_keyring

$ apt-get install python-pip
$ easy_install keyring
$ easy_install mercurial_keyring
$ cat <<'EOF' > /etc/mercurial/hgrc
mercurial_keyring =

Prompt password for the first time:

$ cd my/local/hg/repository
$ hg push http://<user>
pushing to http://<user>
searching for changes
http authorization required
realm: Restricted
user: <user> (fixed in .hg/hgrc)
remote: adding changesets
remote: adding manifests
remote: adding file changes
remote: added 1 changesets with 1 changes to 1 files
Automate other times:

<hg cmd="push" destination="">
  <auth user="ant4hg" mode="keyring" />