Set version using git tags

The snapcraft.yaml file of my Snap package is in a GitLab project which we pull and build the Snap using the LXD provider. Setting the version field to git results in the following error:

fatal: not a git repository (or any of the parent directories): .git

How can I set the version automatically based on the latest git tag of the repository? Can I also dynamically append other information like the build number as well? Something like Go templated YAML files perhaps?