You can edit the config file, then restart the server.
before_install:
- sudo service postgresql stop
- sed -e 's/^port.*/port = 5432/' /etc/postgresql/10/main/postgresql.conf > postgresql.conf
- sudo chown postgres postgresql.conf
- sudo mv postgresql.conf /etc/postgresql/10/main
- sudo service postgresql start 10