Anas bin Malik reported,

On the day of the Trench, the Ansar were chanting, "We are the ones who pledged allegiance to Muhammad to strive in jihad as long as we live."The Prophet ﷺ answered them, saying, "O Allah, there is no life but the life of the Hereafter, so honor the Ansar and the Muhajirun."

Bukhari 2961

Sahih

حدثنا حفص بن عمر حدثنا شعبة عن حميد قال سمعت

أنسا رضي الله عنه يقول

كانت الأنصار يوم الخندق تقول نحن الذين بايعوا محمدا على الجهاد ما حيينا أبدا فأجابهم النبي ﷺ فقال اللهم لا عيش إلا عيش الآخره فأكرم الأنصار والمهاجره

البخاري 2961صحيح
Contents
Reference
Commentary
Ayat
Collection
Sahih Bukhari
Book
Jihad and expeditions
Chapter
Pledge during war not to flee
Numbering
Darussalam 2961
Bukhari 2961