Well, victory gardens were a thing not very long ago: https://en.wikipedia.org/wiki/Victory_garden
But during WWII in Finland there were definitely gardens built by soldiers. As the Soviet Union defended against Germany and its Finnish front was effectively paused, the Finnish soldiers began to build temporary houses on the front lines. Here's a photo from 1943:
http://www.nautelankoski.net/sota/kuvat/sotakuvat/jatkosotak...