'How to update gitlab badges during CI without using personal access token

How to update gitlab badges during the CI without using a personal access token?

I have version badge and want to update it after every build. Therefore, I use maven to get the current version and update the badge using the API.

curl --silent --request PUT --header "Private-Token: $GITLAB_API_TOKEN" https://gitlab.com/api/v4/projects/${CI_PROJECT_ID}/badges/1 -d image_url=https://img.shields.io/badge/version-${VERSION}-blue.svg

However, the GITLAB_API_TOKEN has to be a personal access token. Saving the GITLAB_API_TOKEN in the repository variables allows other developers to access the variable. Therefore, a developer can use another developers personal access key.

Is there another option to update gitlab project badges?

Update: there is a gitlab issue regarding this feature: https://gitlab.com/gitlab-org/gitlab/-/issues/15666



Solution 1:[1]

Check if you still have to do that update, or if GitLab 14.8 (February 2022) does it for you

Latest Release badge for the project

We have added a new badge so you can easily see the version of your latest release right in the project page.

Thank you Jason D’Amour for your contribution!

https://about.gitlab.com/images/14_8/release-latest-release-badge.png -- Latest Release badge for the project

See Documentation and Issue.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 VonC