Voici les différentes étapes pour installer un Runner sous Windows afin de pouvoir faire les exercices de pipeline avec GitLab.
Vérifier votre version de PowerShell :
$PSVersionTable.PSVersion
Voici un exemple :
ou
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 :
Pour beaucoup d’exercices, j’utilise personnellement les commandes linux pour plus de simplicité.
New-Item -ItemType Directory -Force C:\GitLab-Runner | Out-Null cd C:\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 C:\GitLab-Runner au PATH permanent via Panneau de config → Système → Variables d’environnement)
$env:Path = "C:\GitLab-Runner;$env:Path"
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"
C:\GitLab-Runner\gitlab-runner.exe install C:\GitLab-Runner\gitlab-runner.exe start
C:\GitLab-Runner\gitlab-runner.exe status
Résultat :
gitlab-runner: Service is running!
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
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
git clone git@gitlab.com:USER/mon-projet.git
Exemple d’usage :
Scopes (permissions possibles) :
read_repository
write_repository
api
read_api
ci_job_token
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 !
C’est ce qu’il faut utiliser avec la commande :
gitlab-runner register --url "https://gitlab.com" --registration-token "<TON_TOKEN_ICI>"
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 :
git push/pull
gitlab-runner register
Étapes après le clic :
GitLab affichera un écran contenant :
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é) :
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…
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
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
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