Setting Up GitLab Runner on Windows
Thursday, December 29, 2022
Reading time 3 minutes
Increasingly, I resort to GitLab Runners to build my projects. Being able to automate practically the entire configuration (from generating a tag in Git), it’s perfectly possible to publish new software versions, generate documentation, run tests automatically and upload the results of all that to some site, for example Backblaze B2. The result is a “pipeline” that’s a pleasure to use, because it simply works. At the same time, the creation process of each project is documented in the .gitlab-ci.yml file, which is useful to see exactly the steps to follow to get to generate some version of the applications I write.
In this post, however, I’d like to relate a bit about the experience when preparing a new GitLab Runner. Actually it’s not anything out of this world, as that’s quite well explained in the available documentation, but I don’t want to forget my specific case.
Normally, I always prepare a runner with this software installed:
- Git for Windows.
- Visual Studio 2022 Community Edition (particularly from here I choose the “Desktop development with C++” workload).
- Python 3.10 (for 32 and 64 bits).
- The latest version of PowerShell.
- Chocolatey.
- And of course, the latest available version of GitLab Runner for Windows.
Here are the steps I follow for all this:
Step 1. Installing necessary components
All these components are simple to install. In my case, I usually place Python in C:\pythonXXX, where xxx is the version number without the dot (for example, python310 for python 3.10). If the version is for 32 bits, I add a “-32” at the end of the path.
- Download and install the latest version of Git For Windows. Here you can keep the default options.
- Download and install the most recent version of Visual Studio Community Edition. Since I mainly work with Python (and occasionally Flutter), I only need the “Desktop development with C++” workload.
- Download and install the most recent versions of Python for 32 and 64 bits. In the example of installing Python 3.10, their paths in the path would be C:\python310 for the 64-bit version, and C:\python310-32 for 32.
- Install the latest version of PowerShell, as the GitLab runner will complain if the version found is too low. To install PowerShell using WinGet, you can do it like this:
winget install Microsoft.PowerShell
- From PowerShell with administrative privileges, install chocolatey with the following group of commands:
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
Step 2. Install GitLab Runner
The last thing is practically to follow what’s written in the GitLab documentation.
- Download the latest version for Windows (Or for 32 bit) of the executable for GitLab Runner. In the documentation it’s recommended to rename the file so it’s simply called gitlab-runner.exe.
- Create a directory to host the file, for example C:\gitlab.
- Once gitlab-runner.exe is in its directory, through a shell, execute the command to register it:
./gitlab-runner.exe register
- Follow the steps indicated by the assistant (write the URL of the instance to register, paste the Token obtained in the same instance (administration>runners), choose shell as executor and add tags). Once this point is finished, the runner should have been successfully registered.
- Install the runner as a system service, with:
./gitlab-runner.exe install
- Start the service manually, with:
./gitlab-runner.exe start
At this point, it’s advisable to restart the host computer before being able to execute tasks in GitLab Runner. Once restarted, everything should be operational and the Runner will be perfectly capable of taking any task and building what it’s asked. It’s important that some of the tags specified also be used in the .gitlab-ci.yml files, so the runner is assigned for those tasks.