0

I've been having a problem with the generation of badges in gitlab CI/CD. Specifically, my problem is that I don't know how to link correctly the URL of the image and the link. I've researched the internet, but have not found anything that is really specific about it.

Here is part of my file .yml.

      
eslint: 
  stage: eslint
  tags: 
    - docker
  image: node
  before_script:
    - npm i
    - npm install eslint
  script:
    - npx eslint Exercice-41.js > rapport1.txt #generation du rapport pour l'exercice 1
    - npx eslint Exercice-41.js > rapport2.txt #generation du rapport pour l'exercice 2
  artifacts:
    when: always
    paths:
      - "rapport1.txt"
      - "rapport2.txt"

badges:
  stage: deploy
  image: python:3.6.6
  tags:
    - docker
  before_script:
    - pip install anybadge #installation de anybadge
  script:
    - ./generateBadges.sh # Script de génération des badges
  dependencies:         # Les badges sont générés à partir des rapports s'ils sont disponibles
    - eslint
  artifacts:
    paths:
      - eslint1.svg  # Ces fichiers sont générés par le script genereBadges.sh
      - eslint2.svg
  when: always        ```

It generates the images eslint1.svg and eslint2.svg correctly, as well as the rapports (I can see them in the artifacts. 
I've tried to link them in the following manner:

**Link: **

https://gitlab.ensimag.fr/%{project_path}/-/jobs/artifacts/%{default_branch}/%{commit_sha}/raw/rapport1.txt?job=eslint

**Badge image URL**

[https://gitlab.ensimag.fr/%{project_path}/-/jobs/artifacts/%{default_branch}/%{commit_sha}/raw/eslint1.svg?job=badges](https://www.stackoverflow.com/)

I've also tried to change the links but it doesn't generate anything really. 
I don't know what is the problem or why is not showing. Probably, the problem is in the link/url, but I don't know exactly how to do them. I tried countless changes, and generate the badges using the script bellow. It basically counts the ocurrences of error and warnings. 


#!/bin/bash
NBERR=$(grep -w "error" rapport1.txt | wc -l)
NBWARN=$(grep -w "warning" rapport1.txt | wc -l)
color="green"
if \[\[ $NBERR \> 0 \]\]
then
color="red"
else if \[\[ $NBWARN \> 0 \]\]
then
color="orange"
fi
fi
anybadge -o -l "ESLINT1" -v "$NBERR $NBWARN" -c "$color" -f "eslint1.svg"

As I said before, it generates the images, but I don't know how to link them
Thank you very much for any help,

0 Answers0