A man came to the Prophet ﷺ and asked, "What do you say about a man who goes out to fight seeking both reward and renown? What will he receive?"The Messenger of Allah ﷺ replied, "He will receive nothing."The man repeated the question three times, and each time the Messenger of Allah ﷺ told him, "He will receive nothing."Then he said, "Allah accepts only those deeds done sincerely for Him and seeking His face."
أخبرنا عيسى بن هلال الحمصي قال حدثنا محمد بن حمير قال حدثنا معاوية بن سلام عن عكرمة بن عمار عن شداد أبي عمار
جاء رجل إلى النبي ﷺ فقال أرأيت رجلا غزا يلتمس الأجر والذكر ما له فقال رسول الله ﷺ لا شيء له فأعادها ثلاث مرات يقول له رسول الله ﷺ لا شيء له ثم قال إن الله لا يقبل من العمل إلا ما كان له خالصا وابتغي به وجهه
[Its isnad is hasan]. It is found in Kubra, hadith no. 4348, and Iraqi graded it hasan in his Takhrij Ihya.