Custom Bamboo variables from Git tags or composer.json

How can I create a Bamboo variable that is assigned the value of the Git tag of the build? Alternatively, how could I get the version number from composer.json and use that as a Bamboo variable?

Thank you 🙂