Praise be to Allaah.
If you are sent to wage war against the Muslims, then it is not permissible for you to take part at all. Helping the disbelievers against the Muslims is a form of major kufr which puts one beyond the pale of Islam. Allaah says concerning one who supports the mushrikeen (polythiests) (interpretation of the meaning):
“And if any amongst you takes them (as Awliyaa’, i.e., friends), then surely, he is one of them”[al-Maa’idah 5:51]
With regard to how you may get out of this situation, and what excuse you can give to get out of this dilemma if it happens, we ask Allaah to help you, and we suggest that you consult some Muslims who have relevant knowledge or experience.
We want to emphasize to you the necessity of finding other employment and of leaving service in the army of the disbelievers, because that implies helping them, strengthening them and increasing the numbers of their fighters and supporters – unless your work can bring some benefits to the Muslims, such as giving information and secrets of the kaafirs to the Muslims so as to help the Muslims, or if your work is purely da’wah (i.e. call to Islam), such as giving khutbahs and leading prayers for the Muslims in the disbelievers army whilst also advising them to avoid any work that will strengthen the disbelievers. We ask Allaah to keep you safe from temptation and to give you a good end in this world and in the Hereafter.
http://www.islamqa.com/en/ref/14004