Andrea Pirlo has confirmed he will retire from football when his New York City contract expires in December.