[noun] + がてら [verb ます-stem] + がてら
AがてらB means you do A and use the same outing to do B as well: "while taking a walk, I stopped at the shop". It follows a noun of action (さんぽ散歩, かいもの買い物, りょこう旅行) or a verb's ます-stem, and the second half is usually a verb of going somewhere or dropping in.
A verb goes in the ます-stem: ×運動するがてら. With a する-noun, the noun alone is enough: さんぽ散歩がてら is more common than さんぽ散歩しがてら.
がてら is a little bookish but common in speech and writing alike. The everyday equivalent is ついでに. In formal letters and business visits, かたがたdoes the same job with nouns like お礼 and ご挨拶.