This term for white, English-speaking Americans has an interesting story attached to its etymology. Unfortunately, like so many of the interesting stories recounted in these pages, this one is not true. The story does have some facts to recommend it, notably the timing of its entry into English. The earliest English-language cite of Gringo in the OED2 is from 1849 by John Woodhouse Audubon, the son of the artist. Also, the song in question was popular during the war years.
Partridge records a variant of the tale.
In his version it was not Yankees, but rather that it was Irish volunteers in Bolivar's army that were fond of singing the song. While this would take the origin of the term back a few decades, it is not far enough back. According to Rawson, it appears in the Diccionario Castellano in 1787. That dictionary says that it was used in Malaga to refer to anyone who spoke Spanish badly, and in Madrid in reference to the Irish. Given its 1849 English debut, it seems likely that it was in fact brought back by U.S. soldiers, but had nothing to do with any songs.