  We show obstructions to the existence of a coclosed $G_2$-structure on a Lie
algebra $\mathfrak g$ of dimension seven with non-trivial center. In
particular, we prove that if there exist a Lie algebra epimorphism from
$\mathfrak g$ to a six-dimensional Lie algebra $\mathfrak h$, with kernel
contained in the center of $\mathfrak g$, then any coclosed $G_2$-structure on
$\mathfrak g$ induces a closed and stable three form on $\mathfrak h$ that
defines an almost complex structure on $\mathfrak h$. As a consequence, we
obtain a classification of the 2-step nilpotent Lie algebras which carry
coclosed $G_2$-structures. We also prove that each one of these Lie algebras
has a coclosed $G_2$-structure inducing a nilsoliton metric, but this is not
true for 3-step nilpotent Lie algebras with coclosed $G_2$-structures. The
existence of contact metric structures is also studied.
