How to use relative links to job artifacts?

Replace this template with your information

Describe your question in as much detail as possible:
A copy of the repository is here: cdwijs / markdown-test · GitLab
I have a CI/CD job that generates a .png file. I can embed that .png file in the README.md file like this:

![graph](https://git.lumc.nl/crldewijs/markdown-test/-/jobs/artifacts/main/raw/html/dot_inline_dotgraph_1.png?job=deploy)

This works fine, but when the repository is forked, the readme.md still uses the diagrams from this repository, instead of the forked repositories, resulting is stale graphs that are no longer generated from the correct repository. Therefore I want to use relative links.

This does not result in a graph, just a link:

![graph](./jobs/artifacts/main/raw/html/dot_inline_dotgraph_1.png?job=deploy)


When I click he link, I see the link comes out like this:

https://git.lumc.nl/crldewijs/markdown-test/main/jobs/artifacts/main/raw/html/dot_inline_dotgraph_1.png?job=deploy

When I put the working and the non-working link under each other, I see the non-working link has “main” extra in the middle:

https://git.lumc.nl/crldewijs/markdown-test/-/jobs/artifacts/main/raw/html/dot_inline_dotgraph_1.png?job=deploy (working)
https://git.lumc.nl/crldewijs/markdown-test/main/jobs/artifacts/main/raw/html/dot_inline_dotgraph_1.png?job=deploy (not working)

What is the correct way to relative link to the image?

  • What version are you on? Are you using self-managed or GitLab.com?
    I have a self-managed version GitLab Community Edition 14.6.0

  • Add the CI configuration from .gitlab-ci.yml and other configuration if relevant (e.g. docker-compose.yml)
    See also cdwijs / markdown-test · GitLab

image: gcc

variables:
    GIT_SUBMODULE_STRATEGY: recursive #https://docs.gitlab.com/ee/ci/git_submodules.html

deploy:
  stage: deploy
  before_script:
     - apt update && apt -y install doxygen graphviz
  script:
     - doxygen
  artifacts:
    paths:
     - ./html/dot_inline_dotgraph_1.png
#     - ./html/index.html
     

Thanks for taking the time to be thorough in your request, it really helps! :blush:

Hi @cdwijs

Maybe this is overkill, but if you need the exact URL of the project in the README, then I think you probably need a pipeline to insert it.

The predefined variable CI_PROJECT_URL can be used to get the text that you want, so you would just need a little job in the pipeilne to run sed (or similar) over the README file.