Gecko
Gecko

Reputation: 152

GitLab: Exposing value generated from CI to UI

For a lecture exercise at my university we have to write some code to solve a specific problem. Depending on how well our solution performs we get assigned a score. This is all achieved by running a single script that gives you a result which makes it perfect to run over CI.

Now this is a group project so I'd love to have some way to report the score back in the UI e.g. when performing merge requests so I don't have to scroll through the terminal output each time.

Usually one would use artifact reports for this. While the majority of these seem rather application specific (e.g. junit test reports), it looks like the dotenv report is the closest to what I want.

However I have found no way to expose the values directly in the UI. To my knowledge artifact reports should show up as widgets in the merge request view. However I found this not to be the case for me.

What would be a way to expose the value generated when running the CI to quickly see the score a specific branch or commit achieved?

 

Minified CI config of what I currently have

image: python

run-test:
  script:
    # These are some logs generated by running the validation script
    - echo 1,2,3,4 > some_logs.csv
    # This is the result value I'd like to expose
    - echo result=12.34 > results.env

  artifacts:
    paths:
      - some_logs.csv
    reports:
      dotenv: results.env

and my university runs GitLab CE 13.7

Upvotes: 1

Views: 364

Answers (1)

Gecko
Gecko

Reputation: 152

Based on Arty-chan's comment I updated my CI config to perform a POST request to GitLabs API.

Sample config:

image: python

run-test:
  script:
    # These are some logs generated by running the validation script
    - echo 1,2,3,4 > some_logs.csv
    # This is the result value I'd like to expose
    - echo result=12.34 > results.env
    # Only perform POST if $CI_MERGE_REQUEST_IID is set
    - '[ -z "$CI_MERGE_REQUEST_IID" ] && curl --request POST --header "PRIVATE-TOKEN: <your API token>" "https://<instance url>/api/v4/projects/$CI_PROJECT_ID/merge_requests/$CI_MERGE_REQUEST_IID/notes?body=<message>"'

  artifacts:
    paths:
      - some_logs.csv

Note that all <...> need to be replaced with the appropriate values. Also note that $CI_MERGE_REQUEST_IID should be set on merge request but I wasn't able to achieve this consistently.

You will want to store <your API token> as a CI variable to not leak it. Preferably use a project access token for this token.

Upvotes: 1

Related Questions