Gitlab-Runner Windows 服务:使用管理权限构建

Hub*_*mas 5 windows-services administrator gitlab-ci gitlab-ci-runner

问题

  • 如果在本地终端中以“以管理员身份运行”启动运行,则构建服务器上 Powershell 中的 gitlab-runner 会成功完成(vb6.exe、devenv.com、msbuild.exe),而在作为配置为本地管理员的 Windows 服务运行时会出现错误

期望的行为

  • 通过 gitlab-runner 作为独立构建服务器上的 Windows 服务,以管理权限构建项目(vb6.exe、devenv.com、msbuild.exe)

配置

  • Windows Server 2019,Gitlab-Runner v.14.3.2 64位,powershell模式,使用本地管理员帐户运行的服务
  • Visual Studio (VS) 构建需要管理员权限才能实现 VB6 UI (VS VB98) 和 VB6/C# (VS 2019) 项目之间的互操作性。在构建 VS 期间,如果在 VS 解决方案的子项目中选择了互操作模式,则会在 Windows 注册表中写入内容(因此必须具有管理员权限)。

尝试一下

  • 安装 gitlab-runner 作为https://docs.gitlab.com/runner/install/windows.html推荐的服务

  • 暂时停用用户帐户控制但没有成功

  • 修改了 gitlab-ci.yml 以使用 Powershell 命令调用 vb6.exe、devenv.com 和 msbuild.exe Start-Process -Verb runAs -Wait devenv.com ...,但最终出现错误,devenv.com因为Start-Process似乎只接受以*.exeas 文件结尾的应用程序。devenv.exe正在工作,但未通过 Start-Process 返回/关闭新的终端会话,最终导致挂起的 gitlab-ci-build-script 。此外,构建脚本的终端消息不再可见,因为它们正在由 . 创建的新终端会话中运行Start-Process

  • 停用 gitlab-runner 服务并通过 Windows 自动启动文件夹启动:运行 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,但配置的用户需要在每次系统启动时登录,这不是构建服务器所需的行为。

  • gitlab-runner.exe/vb6.exe/devenv.exe/msbuild.exe - 右键单击​​ - 属性 - 兼容性 - 更改所有用户的设置 - 复选框:以管理员身份运行所有激活的用户 - 未更改所描述的行为

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`""
Run Code Online (Sandbox Code Playgroud)

小智 0

对我有用的是给我打算安装运行器的用户作为服务登录的权利。转至控制面板 -> 管理工具 -> 本地安全策略 -> 安全设置 -> 本地策略 -> 用户权限分配 -> 作为服务登录。您需要将安装 gitlab-runner 的用户添加到列表中,包括本地域,然后根据https://docs.gitlab.com/runner/install/windows.html安装运行器,同样使用完整用户名与域。