Versioning code

I use git tags. Tag each release with your version number, e.g. ‘v1.0.0’, you can then have a script in your build process that updates the version number in the code based on the current tag, which you can get from the CI_COMMIT_TAG variable ({CI_COMMIT_TAG#v} if you want to exclude the leading ‘v’).

You can also limit your deployment jobs to tags that match the version pattern, e.g.:

rules:
    - if: '$CI_COMMIT_TAG =~ /^v[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9-\.]+)?$/'

And protect ‘v*’ tags as well to limit only allowing certain users to create releases and/or protect CI variables reserved for the deployment job.