Aller au contenu

installation sur windows

Voici les différentes étapes pour installer un Runner sous Windows afin de pouvoir faire les exercices de pipeline avec GitLab.

Avant de commencer

Vérifier votre version de PowerShell :

$PSVersionTable.PSVersion

Voici un exemple :

ou

alt text

Il faut installer la version 7 sinon, cela pose problème avec le Shell et GitLab :

Choisir la version msi pour Windows

puis tester pour obtenir ceci :

alt text

Pour beaucoup d’exercices, j’utilise personnellement les commandes linux pour plus de simplicité.

Créer un dossier GitLab Runner

New-Item -ItemType Directory -Force C:\GitLab-Runner | Out-Null
cd C:\GitLab-Runner

Télécharger le binaire officiel GitLab Runner

Ce fichier vient directement de GitLab — pas besoin de dépendance.

Invoke-WebRequest `
  -Uri "https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-windows-amd64.exe" `
  -OutFile "C:\GitLab-Runner\gitlab-runner.exe"

Ajouter le dossier au PATH temporairement

Ajouter C:\GitLab-Runner au PATH permanent via Panneau de config → Système → Variables d’environnement)

$env:Path = "C:\GitLab-Runner;$env:Path"

Enregistrer le runner

Récupère le token de projet GitLab :

Sur ton projet GitLab –> Settings –> CI/CD –> Runners –> New project runner

Ensuite exécuter :

C:\GitLab-Runner\gitlab-runner.exe register `
  --url "https://gitlab.com" `
  --registration-token "<TON_TOKEN_ICI>" `
  --executor "shell" `
  --description "Local Runner - Shell Executor" `
  --tag-list "shell,windows"

Installer et démarrer le runner

C:\GitLab-Runner\gitlab-runner.exe install
C:\GitLab-Runner\gitlab-runner.exe start

Vérifier qu’il tourne

C:\GitLab-Runner\gitlab-runner.exe status

Résultat :

gitlab-runner: Service is running!

Tester un pipeline simple

Créer un fichier .gitlab-ci.yml à la racine d’un projet :

stages: [build]

hello_windows:
  stage: build
  tags: [shell, windows]
  script:
    - echo "Hello depuis GitLab Runner sur Windows"
    - powershell -Command "$PSVersionTable.PSVersion"

Vérifier : `Commit –> push –> CI/CD –> Pipelines

Vous devez voir votre premier pipeline/job passer au vert

Explications sur les Tokens de GitLab

Le Project Access Token que vous voyez ici (intégrer image) n’a rien à voir avec la clé SSH ! (et pas non plus avec le token du runner dont on a besoin pour gitlab-runner register).

On va donc bien clarifier les trois types de “tokens” que GitLab propose — ils se ressemblent mais ont des usages très différents

Les clés SSH

git clone git@gitlab.com:USER/mon-projet.git

Project Access Tokens

Exemple d’usage :

Scopes (permissions possibles) :

Scope Description
read_repository Lire le code du repo
write_repository Pousser du code
api Accès complet à l’API GitLab
read_api Lecture API (sans modification)
ci_job_token Utilisé par CI/CD

petit exemple :

Si vous voulez qu’un script Python interroge GitLab pour récupérer les issues :

curl --header "PRIVATE-TOKEN: <ton_project_access_token>" https://gitlab.com/api/v4/projects/:id/issues

Mais pour le runner, ce token-là ne sert pas !

Runner Registration Token

C’est ce qu’il faut utiliser avec la commande :

gitlab-runner register --url "https://gitlab.com" --registration-token "<TON_TOKEN_ICI>"

Mais où le trouver ?

Vous verrez apparaître un token du type : GR1348941e8sdf9q6p

C’est celui-là qu’il faut coller dans la commande gitlab-runner register !

On récapitule :

Type de token Où le créer Sert à… Exemple d’usage
Clé SSH Profil GitLab → SSH Keys Authentifier ton PC pour git push/pull Git local
Project Access Token Projet –> Settings –> Access Tokens Script/API externe cURL, Python, déploiement
Runner Registration Token Projet –> Settings –> CI/CD –> Runners Enregistrer un runner gitlab-runner register

Version actuelle de GitLab

Étapes après le clic :

Commande complète à lancer pour enregistrer le runner (Linux, macOS, Windows)

Ensuite, dans PowerShell (Admin) coller la commande suivante (en remplaçant par celui de GitLab) :

C:\GitLab-Runner\gitlab-runner.exe register `
  --url "https://gitlab.com" `
  --registration-token "<LE_TOKEN>" `
  --executor "shell" `
  --description "Local Runner - Shell Executor" `
  --tag-list "shell,windows"

puis le lancement (déjà précisé) :

C:\GitLab-Runner\gitlab-runner.exe install
C:\GitLab-Runner\gitlab-runner.exe start

Vérification

Retourner sur cette même page Settings –> CI/CD –> Runners. Vous verrez apparaître un nouveau bloc Project runners avec le runner marqué :

Local Runner - Shell Executor  online

Et voilà, c’est déjà un bon début…

Configuration du Runner sur GitLab

Renseigne-le ainsi, puis GitLab te montrera l’étape 2/2 avec le token et la commande d’enregistrement.

Que remplir ici

Tags

shell, windows, docker

Ces tags serviront à cibler ton runner dans .gitlab-ci.yml (ex: tags: [shell, windows]).

Run untagged jobs

Laisse décoché (sinon ton runner prendra tous les jobs sans tags).

Runner description

Local Runner - Shell Executor (Windows)

Protected

Laisse décoché (à cocher uniquement si tu veux que ce runner n’exécute que les pipelines des branches protégées).

Lock to current projects

Tu peux cocher pour limiter ce runner à ce projet uniquement.

Maximum job timeout

Laisse vide (hérite du projet) ou mets 3600 (1h) si tu veux être explicite.

Puis clique Create runner.

Après le clic “Create runner” (étape 2/2)

GitLab affiche une page “Register a runner” avec :

un Registration token (commence par GR…)

des commandes prêtes à copier (Windows, Linux, macOS)

Sur ton Windows (PowerShell Admin)

Si tu as installé manuellement le binaire à C:\GitLab-Runner\gitlab-runner.exe :

(image register runner)

exemple :

C:\GitLab-Runner\gitlab-runner.exe register `
  --url "https://gitlab.com" `
  --token "glrt-r70UNu917VFuE-Ppvp83l286MQpwOjE5NzQ3bwp0OjMKdTpoYzY4bhg.01.1j14dgm10" `
  --executor shell

puis :

C:\GitLab-Runner\gitlab-runner.exe start

Faire un push

Sans local : via l’éditeur Web GitLab

Va dans ton projet GitLab –> Code

New file –> nomme-le .gitlab-ci.yml

Colle :

stages: [build]

hello:
  stage: build
  tags: [shell, windows]
  script:
    - echo "OK depuis mon runner Windows"

Commit changes –> GitLab crée un commit (équivalent à un git push) –> pipeline déclenché.

git tag v1.0
git push gitlab v1.0
# ou: git push gitlab --tags

erreurs windows

solution sans tag avec runner linux partagé

stages: [build]

test_runner:
  stage: build
  script:
    - echo "Salut de GitLab Runner Linux (bash) !"
    - uname -a
    - ls -la