Gitlab-Runner Windows service: build with administrative priviledges

Viewed 1225

Problem

  • gitlab-runner in Powershell on build server finishes successfully (vb6.exe, devenv.com, msbuild.exe) if running in local terminal started with "run as administrator", whereas ending up in errors while running as Windows service configured as local administrator

Desired Behavior

  • building projects (vb6.exe, devenv.com, msbuild.exe) with administrative privileges via gitlab-runner as Windows service on isolated build server

Configuration

  • Windows Server 2019, Gitlab-Runner v.14.3.2 64bit, powershell mode, service running with local administrator account
  • Visual Studio (VS) builds need adminstrator privileges for interopability between VB6 UI (VS VB98) and VB6/C# (VS 2019) projects. During building VS writes in Windows Registry if interopt-mode in sub-project of VS solution has been selected (administrator permissions therefore mandatory).

Try outs

  • installed gitlab-runner as service recommended by https://docs.gitlab.com/runner/install/windows.html

  • temporary deactivated User Account Control with no success

  • adapted gitlab-ci.yml to call vb6.exe, devenv.com and msbuild.exe with Powershell command Start-Process -Verb runAs -Wait devenv.com ..., but ended up in errors for devenv.com because Start-Process seems to accept only applications with *.exe as file ending. devenv.exe is working but not returning/closing new terminal session by Start-Process which ends up in a hanging gitlab-ci-build-script. Additionally, terminal messages of the build script are not visible anymore because they are running in a new terminal session created by Start-Process.

  • Deactivating gitlab-runner service and starting via Windows auto-start-folder: running Powershell-Script: Start-Process -FilePath D:\development\gitlab-runner\gitlab-runner -ArgumentList 'run --working-directory D:\development\gitlab-runner --config D:\development\gitlab-runner\config.toml --service gitlab-runner --syslog' -Verb runAs -Wait, but configured user needs to login on every system start which is not the desired behavior of the build server.

  • gitlab-runner.exe/vb6.exe/devenv.exe/msbuild.exe - right click - properties - compatibility - change settings for all users - checkbox: run as administrator for all user activated - did not change the described behavior

gitlab-ci.yml

stages:
  - deploy

variables:
  PLATFORM: 'x86'
  CONFIGURATION: 'Release'

myproject:
  stage: deploy
  when: manual
  tags: [deploying]
  script:
    - Start-Process MSBuild.exe -Wait -Verb runAs -Argument 'AutomatedSetupBuild.proj'
    - Start-Process devenv.com -Wait -Verb runAs -ArgumentList ".\mysolution.sln /Rebuild `"$CONFIGURATION|$PLATFORM`" /Project .\myproject\myproject.vbproj /ProjectConfig `"$CONFIGURATION|$PLATFORM`" /Log"
    - Start-Process vb6.exe -Wait -Verb runAs -ArgumentList "/make `".\vbproject.vbp`" /out `"$env:TEMP/vb6-buildoutput.log`""
1 Answers

What works for me is to give the user I intend to install the runner as right to log on as a service. Go to Control Panel -> Administrative Tools -> Local Security Policy -> Security Settings -> Local Policies -> User Rights Assignment -> Log on as a service . You need to add the user you installed gitlab-runner to the list, including the local domain, and then install the runner according to https://docs.gitlab.com/runner/install/windows.html, also using the full username with domain.

Related