Correct way and rights to execute wsl in powershell in a pipeline

Problem to solve

Execute commands inside a wsl on a powershell executer in gitlab CI/CD pipeline:

  • Pipeline succeed successfull but the wsl commands only producing empty lines
  • When i capture the output into a variable i get only the value "zugriff verweiger/access denied see screen

Steps to reproduce

  • All different typed of debug commands like whoami, ls, pwd, cat passwd (without effect)
  • Different permutation for the wsl command
  • creating a .ps1 script (pic above) to try also commands
  • changing the user and rights inside the Servies management in windows to my user instead of nt-autorität/system
  • smalest pipeline possible like the code below:

Configuration

qsys-system:
  stage: build
  script: 
    - wsl -e bash -c "echo 'Hello World'"

Versions

Please select whether options apply, and add the version information.

  • Self-managed
  • Self-hosted Runners

Versions

  • GitLab 15.11.2
  • GitLab Runner 16.1.0

I think i could be a permission/configuration issue between gitlab/runner/windows but im not sure where to search or what kind of settings could be wrong. Other examples on stackoverflow are exactly working like this.

Any help or directions is highly appreciated

I’ve never used WSL on Windows, but it sounds like specific permissions are necessary for the service account/group for GitLab Runner.

mentions a few things, where I would recommend trying the following first:

  • Make sure WSL is installed and enabled. Run wsl --list in PowerShell to verify it is working.

  • The GitLab runner may not have the necessary permissions to run WSL. Make sure the service account running the runner is added to the “Windows Subsystem for Linux Users” group.

  • Explicitly start the WSL service before trying to use it:

build:
  script:
    - Start-Service WslService
    - wsl --help

I would also recommend checking the Changelog for newer versions, and considering an upgrade to rule out potential bugs with Powershell/WSL.