I am trying to review the basics.
Find the Fourier series for the function $$f(x) =\left\{ \begin{array}{l l} 2x & \quad -\frac{\pi}{2}<x<\frac{\pi}{2}\\ 0 & \quad -\pi<x<\frac{\pi}{2}, \frac{\pi}{2}<x<\pi. \end{array} \right.$$
My attempt:
$$a_0=\frac{1}{\pi}\int^{\frac{\pi}{2}}_{-\frac{\pi}{2}}f(x)dx=\frac{1}{\pi}\int^{\frac{\pi}{2}}_{-\frac{\pi}{2}}2xdx=0$$ $$a_n=\frac{2}{\pi}\int^{\frac{\pi}{2}}_{-\frac{\pi}{2}}2x\cos(nx)dx=\left[\frac{2x}{n}\sin(nx)+\frac{2}{n^2}\cos(nx)\right]^{\frac{\pi}{2}}_{-\frac{\pi}{2}}=0$$ $$b_n=\frac{4}{\pi}\int^{\frac{\pi}{2}}_{-\frac{\pi}{2}}x\sin(nx)dx=\frac{4}{\pi}\left[\frac{\sin(nx)}{n^2}-\frac{x\cos(nx)}{n}\right]^{\frac{\pi}{2}}_{-\frac{\pi}{2}}=\frac{8}{n^2}(-1)^{n+1}$$
Did I do this correctly because I don't have the solution for it?
Not quite. You're off by a constant factor of $\frac{1}{2}$. You still need to integrate over $[-\pi,\pi]$; just because $f$ vanishes outside of $[-\pi/2,\pi/2]$ doesn't mean the domain of integration changes.
Consequently the length of the interval is still $L = 2\pi$, and $$ a_n = \frac{2}{L}\int_{-\pi}^\pi f(x)\cos(nx)~dx = \frac{1}{\pi}\int_{-\pi/2}^{\pi/2}2x\cos(nx)~dx. $$ And similarly with $b_n$. Of course this won't matter for $a_n$ since they're zero, but for $b_n$ you see the difference.
Otherwise I think you've done the integrations correctly.