My experience was quite different, I spent a while in the German military and masturbation was universally acknowledged and accepted as a basic male need, and ejaculating was almost a daily body function like pissing and taking a shit. This was over 20 years ago, so things might have changed, but back then, porn was everywhere (mags and VHS/DVD) and was shared and exchanged, jo comments and jokes happened, and yes people did get caught but nobody got disciplined or reprimanded because of it, and it is absolutely beyond me as to why that would happen, shaming a man for doing what's natural to him. Maybe thats a US thing? Also, this was military service so we were a bunch of horny 18 and 19 and 20 year olds away from gfs and pussy, so stuff is gonna happen, there were even a few circle jerks over porn, and people did get caught.
Speaking of getting caught, I actually caught my commander back then, which shows how common and not a big deal it was. He was in his early 50s, a gray haired silver fox, killer shape body not just for his age, and packing serious meat, a real case of 'authority cock'. He was a bit of an asshole tho, quite aggressive and yelled a lot, stereotypical drill instructor, and very comfortable with nudity and instilled that into a of us, his motto being 'we are all men here, no need to behave like a bunch of girls '.
We frequently had power marches through the forest and one time he called for a collective piss break, he was first one to unzip and we all lined up, and he yelled 'everyone number 1, hope nobody needs a number 2. Save the number 3s for later' (there was a masturbation comment).
Once when pressed for time he held a squad meeting with us in his quarters while he was in and out of the shower, he just carried on with his business and the meeting while he was toweling off in front of us, and we all got a good look at his porn stash when he opened a drawer to reach for fresh underwear (he was clearly into big tits based on the magazine covers).
Some time after that, me and two of my fellow squad members urgently needed to talk to our commander about something (too long ago not sure what the issue was) so we went to his quarters and heard the shower running so not thinking anything stepped into the bathroom which was a small gang shower with like 3 shower heads and we catch him furiously whacking a massive erection. He saw us and was like "what the hell, get lost and wait outside till I'm done!". While he was certainly startled he did not freak out or tried to turn around or frantically cover up. After a while he came out, toweling off with a big swinging limp cock, as if nothing at all had happened, and he was like 'ok so what did you need to talk about'. One of the guys was like 'sorry about that before' and coach gave him a glare, snapping 'seriously?? This is the military, we are all men here, so leave your dignity at the door!', and then with a smirk he added 'at least you boys know now what a real man looks like'.
It was not mentioned again, but it perfectly sums up the prevailing attitude.