I think this works but it is a little complicated (too much but I cannot see a faster way).
I claim that I only have to do it for abelian $p$-groups. So I take $p$ a prime numbers and assume that $G,H,B$ are abelian $p$-groups.
- I claim that there exists between $H$ and $G$ a sequence of $p$-groups :
$$H:=H_0\subset H_1\subset ... \subset H_r:=G $$
With $|H_i|/|H_{i-1}|=p$. Now if I can do the extension when $G/H$ is of cardinal $p$, I can extend from $H_0$ to $H_1$ then from $H_1$ to $H_2$... from $H_{r-1}$ to $G$. So it suffices to do it when $G/H$ is of cardinal $p$. This is my assumption now.
Take $x\in G$ such that $x\notin H$ then, because $G/H$ is cyclic of cardinal $p$, any element $g$ of $G$ can uniquely be written :
$$g=hx^l\text{ where } h\in H\text{ and } 0\leq l\leq p-1 $$
Furthermore (again because the quotient is cyclic of order $p$), $x^p\in H$. Take $y\in B$ such that $f(y)=x^p$. Now as a set we define $A:=B\times \mathbb{Z}_p$, any element of $A$ is written as :
$$(b,l)\text{ where } b\in B\text{ and } 0\leq l\leq p-1 $$
Define your function $g$ as :
$$g:B\times\mathbb{Z}_p\rightarrow G $$
$$(b,l)\mapsto f(b)x^l $$
This is a surjective function. I claim that we can choose a group law on $A$ that makes $A$ an abelian group and $g$ a group morphism. Indeed on $A$ set :
$$(b_1,l_1).(b_2,l_2):=(b_1b_2,l_1+l_2)\text{ if } l_1+l_2<p $$
$$(b_1,l_1).(b_2,l_2):=(b_1b_2y,l_1+l_2-p)\text{ if } l_1+l_2\geq p $$
It is obviously an internal law, commutative with a neutral element. The only thing to verify is that this is associative. Well I leave this to you (it is a carefull study but this works, actually one can sees that changing $B$ into $H$ you get the law of $G$). Now it is obvious (almost) to see that $g$ is then a group morphism which verifies all the properties.