You don't have to give away the ending as long as you set the players' expectations correctly. Make sure they know that this is a heroic, but gritty and realistic campaign where they will routinely run into challenges too big to just attack head-on unless they're really looking to make a heroic last stand and die gloriously.
Then, make sure they do regularly come across things that could easily kill them all if they don't have both luck and good strategy on their side, and occasionally come across things that will wipe them out if they do anything but back away quietly. Maybe they can come back when they're stronger, maybe not. Encourage wisdom checks for assessing threat levels of encounters. Consider making it an official skill that somebody can have proficiency in. (Assuming the players aren't seasoned enough to just know off the top of their head how hairy the monsters ahead are and which specific questions to ask about the circumstances.)
Since this is a war, draw out your maps and plot out the campaign strategies of the opposing sides. Give the players a chance to learn what those strategies will be and opportunities to disrupt the enemy, or boost performance of allies. Depending on what they come up with, maybe this band of valiant heroes really can change the course of the war. Probably not... But stranger things have happened.
Don't railroad them into taking part in the last stand. Don't prevent them from starting the evacuation early and escaping once they realise what's going to happen. They need to feel like their decisions matter, at least to their own characters. Even if they're somehow still just low-level grunts with no respect by level 15, they could at least desert if they wanted to.
If they've weakened the enemy enough, and have devious enough defense plans, maybe they can even win. A band of four or five in the middle of a clash between powerful nations probably won't turn the tide by themselves, but it does happen. Make them work for it, but if they deserve it, give it to them.
I'd suggest making sure they know to make full use of minions and sidekicks and hired help. Make them do the bookwork obviously, you're busy enough, but a realistic adventuring party for this kind of thing is probably between twenty and fifty, so if they're not part of the official army, that's about the size group of allies they should be looking to collect up. A lot of them can just be low-level nearly-nameless grunts who schlepp packs and hold the horses and keep watch and dig ditches. They can slowly morph into specialists over time to fill in gaps in the party's abilities and reinforce critical ones.
This can make sacrificing a character here and there over the course of the campaign easier as well since they'll both have a variety to choose from, and replacement candidates to be the player's main avatar already on the scene. The "gritty" campaign I'm currently running everybody has two mains and three or four trainees working their way up. The context is it being a player-run mercenary company, so they have to balance cost of wages against what skills and muscle they'll need for the job they're taking. In your setting they're doing it for king and country rather than cold, hard cash (probably) but a similar arrangement both eases the shock of losing a character and will let them accumulate enough power that it feels like their actions actually matter. If they're charismatic, bold, and successful maybe they really will matter enough. If they're not then, when they get wiped out at the end, you want them saying, "oh, yeah, I should have seen that coming and prepared more thoroughly," not, "Stupid, rigged campaign that's impossible to win."
Which isn't to say that you don't give them plenty of opportunities to indulge the laziness which will lead to your desired outcome. Just that, ideally, they'll blame themselves when it's all over.
And, if you're new to running big story arcs like this, I'd suggest spending quite a bit of time in the early phases where it handles like a typical dungeon crawl, and then slowly turning it more toward letting the players pick their strategy and involvement in the war as you get to know them and they get comfortable with the campaign setting. What they will choose to do is probably more entertaining than the canned ending you had in mind anyway. If they veer off in some other direction, that's fine. They can hear the bards singing the praises of the noble heroes who sacrificed themselves to evacuate the capitol after the fact and experience a glimpse into an alternate timeline where it was them if you want.