كتاب الإمارة
33  
The Book on Government
(18)
Chapter: 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
(18)
باب اسْتِحْبَابِ مُبَايَعَةِ الإِمَامِ الْجَيْشَ عِنْدَ إِرَادَةِ الْقِتَالِ وَبَيَانِ بَيْعَةِ الرِّضْوَانِ تَحْتَ الشَّجَرَةِ
Sahih Muslim 1856 b

It has been narrated (through a different chain of transmitters) on the authority of Jabir who said:

While swearing fealty to the Prophet (ﷺ) we did not take the oath to death but that we would not run away (from the battlefield).
وَحَدَّثَنَا أَبُو بَكْرِ بْنُ أَبِي شَيْبَةَ، حَدَّثَنَا ابْنُ عُيَيْنَةَ، ح وَحَدَّثَنَا ابْنُ نُمَيْرٍ، حَدَّثَنَا سُفْيَانُ، عَنْ أَبِي الزُّبَيْرِ، عَنْ جَابِرٍ، قَالَ لَمْ نُبَايِعْ رَسُولَ اللَّهِ صلى الله عليه وسلم عَلَى الْمَوْتِ إِنَّمَا بَايَعْنَاهُ عَلَى أَنْ لاَ نَفِرَّ ‏.‏
Reference : Sahih Muslim 1856b
In-book reference : Book 33, Hadith 105
USC-MSA web (English) reference : Book 20, Hadith 4577
  (deprecated numbering scheme)