如何在gitlab上使用`pwsh`代替powershell?

问题描述 投票:0回答:1

这是我的简单场景:我想在我构建的图像中执行一些最小的冒烟测试。以下效果很好:

docker 2022:
  stage: test
  image: mcr.microsoft.com/windows/servercore:ltsc2022
  script:
    - echo "Hello World!"

现在,如果我使用缺少

powershell
的图像(但存在
pwsh
),则会出现以下错误:

pwsh sdk 7:
  stage: test
  image: mcr.microsoft.com/dotnet/sdk:7.0
  script:
    - echo "Hello World!"

通过阅读其他帖子,我偶然发现:

但这似乎不适合我(我们正在使用 gitlab SaaS),而且我不想更改现有的“powershell”运行程序(ref)。

是否有任何其他机制可以构建 docker 映像,以便使用“pwsh”代替“powershell”(AFAIK 语法是等效的)。


可供参考的失败是:

Running with gitlab-runner 16.6.1 (f5da3c5a)
  on Windows-Docker-runner-2 [...]
Preparing the "docker-windows" executor
Using Docker executor with image mcr.microsoft.com/dotnet/sdk:7.0 ...
Pulling docker image mcr.microsoft.com/dotnet/sdk:7.0 ...
Using docker image sha256:e01215b24dc6dc2849927b4f1a828bc7f5535fe1d45ab3eafb55f6e4c376e65a for mcr.microsoft.com/dotnet/sdk:7.0 with digest mcr.microsoft.com/dotnet/sdk@sha256:e44ea6d4cd019913b80726896e1127cd3fd6bd0f5c1d2074be02da3e54931127 ...
[...]
Getting source from Git repository
Skipping Git repository setup
Skipping Git checkout
Skipping Git submodules setup
Executing "step_script" stage of the job script
Using docker image sha256:e01215b24dc6dc2849927b4f1a828bc7f5535fe1d45ab3eafb55f6e4c376e65a for mcr.microsoft.com/dotnet/sdk:7.0 with digest mcr.microsoft.com/dotnet/sdk@sha256:e44ea6d4cd019913b80726896e1127cd3fd6bd0f5c1d2074be02da3e54931127 ...
Cleaning up project directory and file based variables
ERROR: Job failed (system failure): Error response from daemon: container 937a9b5bca31aca5aed9a4bc75e286d5d5cae1ab8d7af4d83a60eff9c688fb75 encountered an error during hcs::System::CreateProcess: powershell -NoProfile -NoLogo -InputFormat text -OutputFormat text -NonInteractive -ExecutionPolicy Bypass -Command -: failure in a Windows system call: The system cannot find the file specified. (0x2) (exec.go:78:1s)

地点:

...
[[runners]]
  name = "Windows-Docker-runner-2"
  executor = "docker-windows"
  shell = "powershell"
...

pwsh
似乎正在工作:

> docker run mcr.microsoft.com/dotnet/sdk:7.0 pwsh --version
PowerShell 7.3.11
gitlab-ci gitlab-ci-runner
1个回答
0
投票

这是我当前的黑客解决方案:

# escape=`

FROM mcr.microsoft.com/dotnet/sdk:7.0

# Cannot use mklink on nanoserver for now:
# https://github.com/moby/moby/issues/37024
# RUN mklink /h "C:\Program Files\powershell\powershell.exe" "C:\Program Files\powershell\pwsh.exe"

# plain copy for now:
RUN copy "C:\Program Files\powershell\pwsh.exe" "C:\Program Files\powershell\powershell.exe"
© www.soinside.com 2019 - 2024. All rights reserved.