gitlabgitlab-ci-runner

Using windows PC as a Runner


How can a local/on premise Windows PC be integrated as a Runner in a Gitlab CI/CD pipeline?

The documentation on installing and registering a runner focuses on Windows Docker, but for our specific purposes, the actual runner has to be a full-blown Windows 11 machine since we have to use software, that can't be installed on a Windows Image.


Solution

  • Trying to answer your question in an automated way to redistribute or reuse if necessary:

    1. Create a file in PowerShell extension "name_script_whatever_you_want.ps1" with something like this:

      # GitLab Runner Configuration
      $myRunnerFolder = "C:\GitLab-Runner"
      $myRunnerBinary = "$myRunnerFolder\gitlab-runner.exe"
      $myGitLabToken = "your_gitlab_token"
      
      # Replace with your GitLab URL
      $myGitLabURL = "https://gitlab.example.com"
      
      # Create the Runner folder (if it doesn't already exist)
      New-Item -ItemType Directory -Path $myRunnerFolder -Force
      
      # Download the runner binary
      Invoke-WebRequest -Uri "https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-windows-amd64.exe" -OutFile $myRunnerBinary
      
      # Restrict write permissions on the runner folder!!!
      $Acl = Get-Acl $myRunnerFolder
      $Acl.SetAccessRuleProtection($true, $false)
      Set-Acl -Path $myRunnerFolder -AclObject $Acl
      
      # Run the service using the GitLab Token (Here is your solution without docker '--executor shell')
      Start-Process -FilePath $myRunnerBinary -ArgumentList "register --url $myGitLabURL --registration-token $myGitLabToken --executor shell --description 'My Runner Name' --tag-list 'local,shell'"
      Start-Process -FilePath $myRunnerBinary -ArgumentList "install"
      Start-Process -FilePath $myRunnerBinary -ArgumentList "start"
      
      # Update the configuration as needed...
      # For example, to allow multiple concurrent jobs update the concurrency in:
      # C:\GitLab-Runner\config.toml
      
      Write-Host "GitLab Runner is installed and running!"
      

    I haven't tested the script, so if there are any errors, please let me know and I'll correct and reword the answer.

    You can change your config.toml file as the doc says, by changing the following:

    [[runners]]
    name = "shell executor runner"
    executor = "shell"
    shell = "powershell"
    

    Hope it helps!