Gitlab CI integration

Greenspector Variables

  • If you do not already have an existing analyse (or application) on your Greenspector Studio account, create one

  • Find your token on your Greenspector Studio UI (in the user account menu)

  • Create two variables on Gitlab (Settings > CI/CD) : GREENSPECTOR_APP_NAME with the name of your analyse (or application) and GREENSPECTOR_TOKEN with your TOKEN

image-20240307-154730.png

Greenspector Installation

In order to run measure on Greenspector Power Test Cloud from your GitLab CI, you need to download and install the Greenspector CLI module. To do this, 2 solutions:

  1. A guided installation with a predefined script (installationGreenspector.sh). A simple solution if your Gitlab CI environnement is “classic”.

  2. A specific installation if our script is not compatible with your environment

Guided installation

Here are the prerequisites for this installation :

  • An internet access to your Greenspector Core Server.

  • curl (To download Greenspector CLI)

  • jq (To parse the Greenspector JSON module definition and get the URL of the Greenspector CLI and the last version)

NB: If you use docker to run your CI, you can use a public docker image that is compatible with curl and jq or that has already installed it like cfmanteiga/alpine-bash-curl-jq. The only thing you would need (if it is an alpine image) is to link the library used by Greenspector CLI. This is simply done by adding the following command line somewhere in your .gitlab-ci.yml file before using our tools:

mkdir /lib64 && ln -s /lib/libc.musl-x86_64.so.1 /lib64/ld-linux-x86-64.so.2

The installGreenspector.sh script permit to manage this download.

You need to add these lines to your ./gitlab-ci.yml file:

image: python:3.7-alpine3.9 script: - apk add --no-cache curl bash jq - mkdir /lib64 && ln -s /lib/libc.musl-x86_64.so.1 /lib64/ld-linux-x86-64.so.2 - chmod +x installGreenspector.sh - ./installGreenspector.sh -t "$GREENSPECTOR_TOKEN" -o "Linux"

Line 1 : image which respect the prerequisites

Line 3 : Installation of bash, curl and jq

Line 4 : Link the library used by Greenspector CLI

Line 5 : Make installGreenspector.sh executable

Line 6 : Launch of the script with Greenspector Token (defined in the Gitlab project variables) and the OS of your image.

Specific installation

You need to call the Greenspector API to gather Greenspector CLI installation with the following routes: https://app.greenspector.com/api/modules

You will need to use your Greenspector Token to call this route. For example:

curl -s -H "Private-Token: $token" https://app.greenspector.com/api/modules >modules.json

The response of the route will be as the following:

{
"version": "v2.21.3",
"modules": [
{
"name": "Greenspector CLI",
"version": "2.10.1",
( …)
"archs": [{
"name": "64-bit",
"links": {
"Windows": "/downloads/cli/greenspector-2.10.1_windows-amd64.exe",
"Linux": "/downloads/cli/greenspector-2.10.1_linux-amd64",
"Darwin / Mac OS": "/downloads/cli/greenspector-2.10.1_darwin-amd64"
}
},

(…)

  • Find the object from the array modules with the name Greenspector CLI

  • Find the version path.

    • If you have already installed Greenspector CLI but with a different version, you may update your installation with this new one

  • In archs, find the object with the name "64-bit"

  • In this object, find the object with the key corresponding to your OS

  • The value corresponding is the url to download the Greenspector CLI.

  • Download the file

  • Rename the file to gspt (or other name which will be simpler, however all our user guides will use this name)

  • Change the property of the file to make it executable

  • Initialise the CLI with the following command with $GREENSPECTOR_TOKEN the token saved in the Gitlab CI variables

[Name of the Greenspector CLI] i -a https://app.greenspector.com/api -p "$GREENSPECTOR_TOKEN"