如何从gitlab CI在Windows上运行wsl?

qv7cva1a  于 2023-08-07  发布在  Windows
关注(0)|答案(1)|浏览(175)

我使用的是Windows 10 Pro,并安装了带有pwsh shell的gitlab runner。我尝试启动wsl,但Gitlab返回空输出和错误代码。gitlab ci error My .gitlab-ci.yml

Build WSL2 Ubuntu 22.04:
  stage: Build
  tags:
    - windows
  script:
   - Write-Output "hello"
   - dir C:\Windows\System32\wsl.exe 
   - Get-Service WslService
   - wsl.exe --help

字符串
我正在尝试启用gitlab runner debug log,我看到了什么:

Checking for jobs... received                       job=42465 repo_url=https://gitlab.clive.tk/kubes/wsl2.git runner=rgsws7VJz
Processing chain                                    chain-leaf=[0xc000956b00 0xc000957080] context=certificate-chain-build resolve-full-chain=true
Certificate doesn't provide parent URL: exiting the loop  Issuer=Certificate Authority IssuerCertURL=[] Serial=1 Subject=Certificate Authority context=certificate-chain-build
Failed to requeue the runner                        builds=1 runner=rgsws7VJz
Running with gitlab-runner 16.1.0 (b72e108d)        job=42465 project=248 runner=rgsws7VJz
  on clivetk rgsws7VJz, system ID: s_f4336df4ca45   job=42465 project=248 runner=rgsws7VJz
Preparing the "shell" executor          job=42465 project=248 runner=rgsws7VJz
Shell configuration: command: pwsh
arguments:
- -NoProfile
- -NoLogo
- -InputFormat
- text
- -OutputFormat
- text
- -NonInteractive
- -ExecutionPolicy
- Bypass
- -EncodedCommand
- JABPAHUAdABwAHUAdABFAG4AYwBvAGQAaQBuAGcAIAA9ACAAWwBjAG8AbgBzAG8AbABlAF0AOgA6AEkAbgBwAHUAdABFAG4AYwBvAGQAaQBuAGcAIAA9ACAAWwBjAG8AbgBzAG8AbABlAF0AOgA6AE8AdQB0AHAAdQB0AEUAbgBjAG8AZABpAG4AZwAgAD0AIABOAGUAdwAtAE8AYgBqAGUAYwB0ACAAUwB5AHMAdABlAG0ALgBUAGUAeAB0AC4AVQBUAEYAOABFAG4AYwBvAGQAaQBuAGcADQAKAHAAdwBzAGgAIAAtAEMAbwBtAG0AYQBuAGQAIAAtAA0ACgA=
cmdline: pwsh -NoProfile -NoLogo -InputFormat text -OutputFormat text -NonInteractive
  -ExecutionPolicy Bypass -EncodedCommand JABPAHUAdABwAHUAdABFAG4AYwBvAGQAaQBuAGcAIAA9ACAAWwBjAG8AbgBzAG8AbABlAF0AOgA6AEkAbgBwAHUAdABFAG4AYwBvAGQAaQBuAGcAIAA9ACAAWwBjAG8AbgBzAG8AbABlAF0AOgA6AE8AdQB0AHAAdQB0AEUAbgBjAG8AZABpAG4AZwAgAD0AIABOAGUAdwAtAE8AYgBqAGUAYwB0ACAAUwB5AHMAdABlAG0ALgBUAGUAeAB0AC4AVQBUAEYAOABFAG4AYwBvAGQAaQBuAGcADQAKAHAAdwBzAGgAIAAtAEMAbwBtAG0AYQBuAGQAIAAtAA0ACgA=
dockercommand:
- pwsh
- -NoProfile
- -NoLogo
- -InputFormat
- text
- -OutputFormat
- text
- -NonInteractive
- -ExecutionPolicy
- Bypass
- -EncodedCommand
- JABPAHUAdABwAHUAdABFAG4AYwBvAGQAaQBuAGcAIAA9ACAAWwBjAG8AbgBzAG8AbABlAF0AOgA6AEkAbgBwAHUAdABFAG4AYwBvAGQAaQBuAGcAIAA9ACAAWwBjAG8AbgBzAG8AbABlAF0AOgA6AE8AdQB0AHAAdQB0AEUAbgBjAG8AZABpAG4AZwAgAD0AIABOAGUAdwAtAE8AYgBqAGUAYwB0ACAAUwB5AHMAdABlAG0ALgBUAGUAeAB0AC4AVQBUAEYAOABFAG4AYwBvAGQAaQBuAGcADQAKAHAAdwBzAGgAIAAtAEMAbwBtAG0AYQBuAGQAIAAtAA0ACgA=
passfile: false
extension: ps1
  job=42465 project=248 runner=rgsws7VJz
Using Shell (pwsh) executor...                      job=42465 project=248 runner=rgsws7VJz
Waiting for signals...                              job=42465 project=248 runner=rgsws7VJz
No referees configured                              job=42465 project=248 runner=rgsws7VJz
Executing build stage                               build_stage=prepare_script job=42465 project=248 runner=rgsws7VJz
Preparing environment                   job=42465 project=248 runner=rgsws7VJz
Using new shell command execution                   job=42465 project=248 runner=rgsws7VJz
Executing build stage                               build_stage=get_sources job=42465 project=248 runner=rgsws7VJz
Getting source from Git repository      job=42465 project=248 runner=rgsws7VJz
Using new shell command execution                   job=42465 project=248 runner=rgsws7VJz
Feeding runners to channel                          builds=1
Feeding runner to channel                           builds=1 runner=rgsws7VJz
Appending trace to coordinator...ok                 code=202 job=42465 job-log=0-544 job-status=running runner=rgsws7VJz sent-log=0-543 status=202 Accepted update-interval=1m0s
Executing build stage                               build_stage=restore_cache job=42465 project=248 runner=rgsws7VJz
Skipping stage (nothing to do)                      build_stage=restore_cache job=42465 project=248 runner=rgsws7VJz
Executing build stage                               build_stage=download_artifacts job=42465 project=248 runner=rgsws7VJz
Skipping stage (nothing to do)                      build_stage=download_artifacts job=42465 project=248 runner=rgsws7VJz
Executing build stage                               build_stage=step_script job=42465 project=248 runner=rgsws7VJz
Executing "step_script" stage of the job script  job=42465 project=248 runner=rgsws7VJz
Using new shell command execution                   job=42465 project=248 runner=rgsws7VJz
Executing build stage                               build_stage=after_script job=42465 project=248 runner=rgsws7VJz
Skipping stage (nothing to do)                      build_stage=after_script job=42465 project=248 runner=rgsws7VJz
Executing build stage                               build_stage=archive_cache_on_failure job=42465 project=248 runner=rgsws7VJz
Skipping stage (nothing to do)                      build_stage=archive_cache_on_failure job=42465 project=248 runner=rgsws7VJz
Executing build stage                               build_stage=upload_artifacts_on_failure job=42465 project=248 runner=rgsws7VJz
Skipping stage (nothing to do)                      build_stage=upload_artifacts_on_failure job=42465 project=248 runner=rgsws7VJz
Skipping referees execution                         job=42465 project=248 runner=rgsws7VJz
Executing build stage                               build_stage=cleanup_file_variables job=42465 project=248 runner=rgsws7VJz
Cleaning up project directory and file based variables  job=42465 project=248 runner=rgsws7VJz
Using new shell command execution                   job=42465 project=248 runner=rgsws7VJz
WARNING: Job failed: exit status 1
                 duration_s=20.3925953 job=42465 project=248 runner=rgsws7VJz
Appending trace to coordinator...ok                 code=202 job=42465 job-log=0-14895 job-status=running runner=rgsws7VJz sent-log=544-14894 status=202 Accepted update-interval=1m0s


但是如果我从powershell windows运行wsl-它启动成功。如何在gitlab ci中运行wsl?

mnemlml8

mnemlml81#

听起来像是WSL在GitLab runner机器上没有正确配置或启用。需要检查的几件事:

  • 确保已安装并启用WSL。在PowerShell中运行wsl --list以验证它是否工作。
  • GitLab runner可能没有运行WSL所需的权限。确保运行runner的服务帐户已添加到“Windows Subsystem for Linux Users”组。
  • WSL需要虚拟化支持。验证BIOS中是否已启用虚拟化。
  • 尝试直接在主机上运行构建,而不是通过Docker,因为Docker可能无法完全访问WSL:
build:
  stage: build
  tags:
    - windows 
  script:
    - pwsh -c "wsl --help"

字符串

  • 在尝试使用WSL服务之前,请显式启动它:
build:
  script:
    - Start-Service WslService
    - wsl --help

  • 检查运行程序日志中与WSL相关的任何错误,以帮助进一步排除故障。

关键是确保WSL在GitLab runner主机上正确设置,并且runner有足够的权限使用它。

相关问题