Given a function $f\!: x\mapsto f(x)$ on some interval $I$ of length $L>0$ one obtains its Fourier expansion by extending $f$ to all of ${\mathbb R}$ periodically using the given $L$ as period length. The coefficients of the Fourier series should then be computed using the standard formulae for period length $L$ and integrating over the interval $I$ where the function $f$ was given in the first place.
In the case at hand we have $I=[0,\pi]$ and $L=\pi$, and the standard formulae give
$a_k={2\over\pi}\int_0^\pi \sin x \cos(2 k x)\ dx,\qquad b_k={2\over\pi}\int_0^\pi \sin x \sin(2 k x)\ dx.$
Now there is the extra condition that we want only $\cos$-terms. In order to enforce this we must make sure that the periodically extended function is even. But here we are lucky: As $\sin(\pi -x)\equiv \sin x$ the extended function is even automatically. This means that in the above formulae the $b_k$ are all zero, and there remains nothing to be done apart from calculating the integrals for $a_k$.
It would be another matter if the given function would not have this symmetry with respect to $x\mapsto \pi -x$, as in the case of $g(x):=\sin{x\over 2}$ $(0 < x <\pi)$. In this case it would be necessary to extend $g$ first to an even function on the interval $[-\pi,\pi]$, whereupon the standard formulae for period length $2\pi$ can be applied to compute the $a_k$.