Self inductance is defined as the induction of a voltage in a current-carrying wire when the current in the wire itself is changing.
The potential difference across an inductor with rate of change of current dI/dt across it is V=L(dI/dt)
Hence work done to build up current I = ∫Vdq = ∫₀ᴵ (L(dI/dt))(Idt) = 1/2LI²