I'm referring to any time period in which "magic" was used effectively in an army or military conquest.
If we define "mage" as a person capable of directing the extra/supernatural "energies" from a non-divine energetic source for the tactical benefit of a military unit or army they are accompanying, the answer would be "never" in terms of "how often" and effectiveness being "none."
If we define "mage" as a person who is seen as capable of being a focal point for the dissemination of extra/supernatural "will" from a divine source for the overall benefit of a military unit or army they are accompanying, the answer would be "all the time" in terms of "how often" and effectiveness being "any time a victory was achieved."
However at this latter point (and this is indeed a very good point worth thinking about), a "mage" then becomes indistinguishable from a priest (as a specialist) or any religious-minded individual (as a generalist) that exists in any military. By these definitions, chaplains are technically battle mages, and any time a victory was ascribed to the pious prayers to a deity, that person was a mage (so pretty much everybody, from Roman to Modern, from soldiers to football players).
These are not flippant questions, because much hinges upon not only definitions of magic/religion, but our own conceptions of magic/religion as different from ancient conceptions of magic/religion. The main problem we have is that we have a false presumption about what ancient magic is, because we want to construct our understanding of an energetic Science™ world of now as more progressive than a superstitious Magic™ world of the past. This is why there's a tendency for us to construct ancient "magic" as somehow "misunderstood science."
Also, we have the influence of Dungeons and Dragons and video games in perpetuating such a fake explanation of ancient magic. Know what the mage's purpose was in D&D? Artillery support. D&D was a tactical combat game set in the medieval era, where all the classes mimic'd world war 2 squad units, Fighter = Assault soldier, Cleric = Medic, Thief = Recon, Mage = Artillery.
To the best of my knowledge, there has only ever been one book on ancient battle "magic", that's the Cesti of Julius Africanus. Except the problem is, the author didn't think the book was a work of magic, he just thought it was a book of secret military tactics. It's constructed as magic because later authors disagreed with him that it wasn't magic, which goes to show you, the problem ultimately lies with the problem of defining magic, and its difference from religion, and its ex post facto assignment by us as somehow misunderstood science.
/u/bitparity has provided quite a useful conceptual framework – 'magic' in terms of direct tactical benefit through the exercising of specific powers, versus being generally seen as bringing about victory through obtaining favour from the enigmatic will of the divine. Now, it may well be that in a 'Western' context, magic in a military context is largely of that second sort and thus indistinguishable from simple piety. But looking at the Qing Empire, I'd contend that a whole spectrum of war-related 'magic' was believed to exist, and that while the actual 'magic' from an empirical standpoint was not in fact 'real', that its psychological effects certainly were.
But let's start from the point of agreement: More general uses of 'magic' to provide some intangible benefit were absolutely a feature of Qing-era warfare. A particular stratagem used by the Qing when defending in a siege was to seek means of deploying yin energy that would counteract the presumed yang energy of the attacking enemy's magic. The typical source, it seems, and hence the technique's prevalence in defensive sieges, was female bodily fluids. During the Wang Lun uprising of 1774 in Shandong, in one city the Qing commanders had naked prostitutes sent up on the walls to urinate over the ramparts and throw animal blood (mimicking menstrual blood) at the enemy in order to suppress their magic, which was apparently able to protect them from bullets after shouting that 'guns will not fire!' A similar technique would be employed against the British by Yang Fang in February 1841. A veteran of Qing wars in Central Asia, Yang Fang was nevertheless convinced that the British were using some form of yang magic to improve the range of their artillery, and according to diarist Liang Tingnan he ordered every ten households to gather women's chamber-pots which could be floated down the Pearl River Delta on rafts. In Julia Lovell's telling of the event she speculates that this was some reference to women's low status in society, but taking into account the response to the Wang Lun rebels it seems reasonable to believe that in fact, there may have been a far more consistent employment of gendered magic in the field. Indeed, during the Taiping War it seems there was at least one instance of the Taiping employing the same stratagem as the Qing in 1774, sending women up on the city walls with their genitals exposed in order to apparently prevent enemy cannon from firing.
While the above shows clear instances of the Qing using magic defensively, it is generally correct to say that Qing forces tended not to cast the first spell. The use of magic was usually something that the Qing's opponents did. For example, the Muslim rebel leader Wang Fulin in the 1780s was said to be able to protect his army from bullets using charms, and had to be picked off by Qing marksmen before his troops could be harmed. During the Second Jinchuan War in the 1770s, the Jinchuan (Tibetan-speakers in Sichuan, largely practitioners of Bön with a minority of Red Hat Buddhists) were believed to be soliciting otherwordly assistance, with monks chanting incantations and Jinchuan armies burying 'devil traps' near Qing armies. Buried curses were in some cases invoked against the Qianlong emperor himself. In the latter cases, we find the employment of magic with far less specific ends in mind, only the solicitation of some sort of intangible support that would lead to victory. But Wang Fulin and Wang Lun's use of specifically bullet-stopping magic does constitute an attempt at using magic to achieve a specific tactical end. Similarly, Qing fears about Red Hat monks were not merely general worries about the solicitation of some vague supernatural force to bring about defeat. Allegedly, the Red Hats were specifically manipulating the weather to slow Qing progress, a belief that seems to have genuinely been held by three senior generals in the Qing campaign who relayed their concerns to the emperor.
However, there is certainly a little bit of Qing magic use, though it either comes through in external sources or is quite oblique. Joanna Waley-Cohen focusses in particular on the Second Jinchuan War, where apparently Tibetan accounts claim that the Qianlong Emperor's friend and advisor, the Gelug cleric Rolpay Dorje, summoned fireballs and dust storms to obfuscate the Jinchuan and bring victory to the Manchus (and, by extension, the Gelug sect). A case of a possibly oblique employment of magic comes in the Chinese accounts, which credit Qing victory in part to Felix de Rocha, Jesuit head of the Bureau of Astronomy, who instructed crews in aiming techniques and designed new cannon to deal with the Jinchuan's stone towers. As Waley-Cohen speculates, perhaps part of the rationale behind employing de Rocha was the idea that one heterodoxy might counteract another.
As noted, it was relatively atypical for Qing armies to employ magic in the field. That does not mean that military ritual was unimportant. However, such rituals were typically constrained to the commencement and conclusion of campaigns in pursuit of general divine favour, not appeals for particular support in particular contexts. As bitparity notes, though, in some ways these appeals to the divine were simply the orthodox corollary to heterodox magic, with the difference to some extent boiling down to whether or not the state approved of the particular religious tradition that the rituals drew from. Nevertheless, the Qing were active in seeking to counter the use of magic by the enemy. In response to news regarding Wang Fulin's death, the Qianlong Emperor angrily rebuked the commander sending the report for humouring his men's superstition about Wang's magic powers, declaring that the real reason for their ineffectiveness was poor training which led to them overshooting the enemy – why else, he asked, could these mystics claim to deflect bullets (typically fired by Chinese musketeers) and not arrows (typically shot by Manchu horsemen)? Green Standard troops (in contrast to Manchu Bannermen) were, he declared, far too prone to pinning the blame for their own personal failures on outside forces. However, this hyper-sceptical attitude was usually displayed ex post facto. During the Second Jinchuan War itself, he ordered his generals to seek to openly counter enemy magic use rather than disregard it entirely, such as by having the 'devil traps' dug up and cast into either fire or water to nullify their power.
There is, however, a specific detail in his instructions that suggests that on the whole, counter-magic was often not actually rooted in a belief in the original magic's efficacy, but instead a performative statement aimed at one side or the other. And that is that, even if officers were unable to locate 'devil traps', that they should create fake ones solely for the purpose of publicly destroying them. The point was to strengthen the morale of the men, not counter any apparently real magic force. A similar logic may have applied in the Wang Lun case, where animal blood was used in place of actual menstrual blood. The significance did not lie in the substance itself, but in the act. It was not important for it to be actual menstrual blood in order that the rebels' yang magic was countered, it was enough that the rebels perceived that their magic was being countered. One example in 1900 of something a little less subtle involves Yuan Shikai, who was engaged in a campaign of anti-Boxer suppression in Shandong province (simultaneous with Qing support for the Boxers in neighbouring Zhili). After a demonstration by a Boxer master of his immunity to gunfire, taking the form of the classic 'magician catching a bullet in his mouth' trick involving a stooge firing a blank, Yuan pulled out his sidearm and shot the master with a live round (think Raiders of the Lost Ark). In this case, a far blunter demonstration of magic's inefficacy achieved the same basic end – discouraging heterodox beliefs.
But the Boxer Uprising also gives us a chance to observe differences in who performed magic. The defining feature of the Boxers to Western observers was of course their use of ritualistic martial arts displays before battle to obtain immunity to gunfire. As with the Wang Lun rebels, all of the combatants were involved in the performance of military magic. But in the case of the Shandong prostitutes or the Jinchuan lamas, it was a group of noncombatants who performed the magic in support of the fighting troops. Senior officers could perform counter-magic, as with Yuan Shikai, and of course the campaign rituals, if viewed as an 'orthodox' equivalent to magic, were presided over by the emperor in the eighteenth centiry. But typically, the employers of specialised magic skills were individuals, such as Rolpay Dorje or Felix de Rocha. With the Boxers, some commanders like Cao Futian could allegedly behead enemies at a distance by waving a stalk of grain or scout out enemy deployments in his dreams. But the most notable case of Boxer magicians were the Red Lanterns, a group of largely adolescent female virgins who were believed to be capable of performing magic feats such as flight or throwing fireballs, or in extreme cases causing the foreigners' artillery to fall apart. Most powerfully, they could remotely light fires and control the winds in such a way as to specifically destroy foreign missions and the homes of Christian converts. The gendering of magic is especially important here, as the Red Lanterns, being virgins, were 'pure' and lacked the sorts of feminine yin energy that dampened masculine yang magic. What do we find in accounts of failed Boxer magic but the appearance of urine, dirty water, menstrual blood, pubic hair, or simply of women?