I'm using Gitlab and Sonarqube and the Sonarqube Plugin SVG Badges.
To represent the Sonarqube state on gitlab I have something like this in my README.md
file:
[![coverage](https://sonar.domain.com/api/badges/measure?key=com.domain:projectname&metric=coverage)](https://sonar.domain.com/component_measures/metric/coverage/list?id=de.domain:projectname)
This works perfect. My badge is shown, the link is working, everything is fine.
Is there some way to build something like:
[![coverage](https://sonar.domain.com/api/badges/measure?key={MYDOMAIN}:{THIS}&metric=coverage)](https://sonar.domain.com/component_measures/metric/coverage/list?id={MYDOMAIN}:{THIS})
I want to provide a skeleton that every Developer just can copy and paste into their README.md
file and the variables are filled into the README automatically, with something like .gitlab-ci.yml
I also tried the permanent Gitlab Variables mentioned here but that wasn't working too!
[![coverage](https://sonar.domain.com/api/badges/measure?key=com.mydomain:$CI_PROJECT_NAME&metric=coverage)](https://sonar.domain.com/component_measures/metric/coverage/list?id={MYDOMAIN}:$CI_PROJECT_NAME)
Anyone has some idea?
The variables in https://gitlab.com/help/ci/variables/README.md are present only in a CI environment (i.e. a job), so you can't use them in the Markdown viewer when displaying the file. - That's a great idea for a feature proposal, though. I opened one - https://gitlab.com/gitlab-org/gitlab-ce/issues/32255. Feel free to chime in.
What you could do is add a placeholder where you want those variables to go and then create a job which sed
's them.
update_readme:
script:
- echo $CI_PROJECT_NAME # Sanity check
- sed -ie "s/{THIS}/$CI_PROJECT_NAME/g" README.md
Note the use of double-quotes (") and not single quotes ('). Using double-quotes will interpolate $CI_PROJECT_NAME
while single-quotes would just retain it's literal value.