It is recommended for the army to swear allegiance to the ruler when intending to fight, and an account of Bay'at Ar-Ridwan beneath the tree Sahih Muslim 1861
Arabic hadith text
وَحَدَّثَنَا إِسْحَاقُ بْنُ إِبْرَاهِيمَ، أَخْبَرَنَا الْمَخْزُومِيُّ، حَدَّثَنَا وُهَيْبٌ، حَدَّثَنَا عَمْرُو بْنُ، يَحْيَى عَنْ عَبَّادِ بْنِ تَمِيمٍ، عَنْ عَبْدِ اللَّهِ بْنِ زَيْدٍ، قَالَ أَتَاهُ آتٍ فَقَالَ هَذَاكَ ابْنُ حَنْظَلَةَيُبَايِعُ النَّاسَ فَقَالَ عَلَى مَاذَا قَالَ عَلَى الْمَوْتِ قَالَ لاَ أُبَايِعُ عَلَى هَذَا أَحَدًا بَعْدَ رَسُولِ اللَّهِ صلى الله عليه وسلم .
Translation
It has been narrated on the authority of Abdullah b. Zaid who said
A person came to him and said: Here is Ibn Hanzala who is making people swear allegiance to him. He (, Abdullah) asked: To what effect? He replied: To the effect that they will die for him. 'Abdullah said: I will never swear allegiance to this effect after the Messenger of Allah (ﷺ).