$$ I=\int_0^{\pi}\frac{1}{(1+\frac{1}{2}\cos x)^2}dx $$
$I$ turns out to be half of integral from $-\pi$ to $\pi$. So we can change the integral to contour integral with unit circle as contour by substituting $z = e^{ix}$. But the function I get is not continuous on the contour.
You are on the right track. By letting $z=e^{ix}$, it follows that $\cos x= \frac{1}{2}\left(z+\frac{1}{z}\right)$ and we get $$I=2\int_{-\pi}^{\pi}\frac{1}{(2+\cos x)^2}dx= \frac{8}{i}\int_{|z|=1}\frac{z}{(z^2+4z+1)^2}dz$$ which is well-defined along the contour. Can you take it from here?