Slaves in the military were common in West Africa from at least the seventeenth century:
The most important privileged slaves in West Africa were the
warriors....The number of slave warriors in western Africa grew during
the seventeenth and eighteenth centuries. They served the state by
fighting, but also by running messages, administering the court and
holding important posts.
Samori Toure, founder of the Wassoulou Empire (1878-98), had an army which included around 30,000 infantry, most of whom were slaves. These male slaves were armed with
imported breech-loading rifles and muzzle-loaders manufactured by
local blacksmiths.
In the Senegambia region of West Africa,
ordinary slaves were divided into two categories : slaves who had been
captured during the countless raiding expeditions, and slaves bought
at the slave markets. The former were kept in special villages both in
time of peace and war. After several years in such villages the
bravest of them were selected to become warriors, and were henceforth
royal slaves. They would fight under the command of the chief, and
he alone had the right to punish them.
Source: Mbaye Guerre, The slave trade within the African continent in UNESCO, The African slave trade from the fifteenth to the nineteenth century
The French also used slaves as soldiers in the French Sudan (now Mali) in the late 19th century. According to the French soldier Joseph Gallieni:
The enlistment bonus is 250 francs. If he is a free man, we give him
the 250 francs and he serves you loyally. If he is a slave, we act as
follows so as to not annoy the master: the master is told when the
slave will receive his bonus and often he takes it and the slave has
nothing.
Cited in Martin Klein, Slavery and colonial rule in French West Africa
Slaves were also used as soldiers in the Dutch colony of New Netherland around the mid 17th century:
The WIC [Dutch West India Company] enlisted its male slaves in
military campaigns against the natives during the Indian war. These
slaves did not bear firearms but instead wielded small axes and
half-pikes.