首页 > 解决方案 > Gitlab CI 在不被要求时尝试运行 powershell

问题描述

我正在尝试使用 gitlab-CI 构建 Web 应用程序。我用这个配置创建了跑步者:

name = "REDACTED"
  url = "REDACTED"
  token = REDACTED
  executor = "docker-windows"
  [runners.custom_build_dir]
  [runners.cache]
    [runners.cache.s3]
    [runners.cache.gcs]
    [runners.cache.azure]
  [runners.docker]
    tls_verify = false
    image = "mcr.microsoft.com/powershell"
    privileged = false
    disable_entrypoint_overwrite = false
    oom_kill_disable = false
    disable_cache = false
    volumes = ["c:\\cache"]
    shm_size = 0

然后我的 .gitlab-ci.yml 看起来像这样

image: microsoft/dotnet:latest
stages:
  - build
  - test
  
before_script:
  - "dotnet restore"
  
node_build: 
  stage: build
  only: 
    - master
  script: 
    - "echo Stage - Build started"
    - "cd ./WebApplication"
    - dir
    - dotnet build

node_test: 
  stage: test
  only: 
    - master
  script: 
    - "echo Stage - Test started"
    - "cd ./WebApplication"
    - dir
    - dotnet build

运行管道时,输出如下所示

Running with gitlab-runner 13.11.0 (7f7a4bb0)
  on REDACTED  REDACTED 
Preparing the "docker-windows" executor
Using Docker executor with image microsoft/dotnet:latest ...
Pulling docker image microsoft/dotnet:latest ...
Using docker image sha256:34f6f2295334d34567c67059f7c28836c79e014d0c4fadf54de3978798640003 for microsoft/dotnet:latest with digest microsoft/dotnet@sha256:61d86fc52893087df54b0579fcd9c33e144a4b3d34c543a94e6a6b376c74285d ...
Preparing environment
Running on REDACTED via 
REDACTED ...
Getting source from Git repository
Fetching changes with git depth set to 50...

Reinitialized existing Git repository in C:/builds/REDACTED /c-sharp-ci-test/.git/
Checking out bbb22919 as master...

git-lfs/2.11.0 (GitHub; windows amd64; go 1.14.2; git 48b28d97)

Skipping Git submodules setup

Executing "step_script" stage of the job script
Using docker image sha256:34f6f2295334d34567c67059f7c28836c79e014d0c4fadf54de3978798640003 for microsoft/dotnet:latest with digest microsoft/dotnet@sha256:61d86fc52893087df54b0579fcd9c33e144a4b3d34c543a94e6a6b376c74285d ...
Cleaning up file based variables
ERROR: Job failed (system failure): Error response from daemon: container e144f05bdd00b4e744554345666afbc008ee2437c7d56bf4a98fbd949a88b1b2 encountered an error during hcsshim::System::CreateProcess: failure in a Windows system call: The system cannot find the file specified. (0x2)
[Event Detail:  Provider: 00000000-0000-0000-0000-000000000000]
[Event Detail:  Provider: 00000000-0000-0000-0000-000000000000]
[Event Detail: onecore\vm\compute\management\orchestration\vmhostedcontainer\processmanagement.cpp(173)\vmcomputeagent.exe!00007FF7D970B1D7: (caller: 00007FF7D96BE70B) Exception(6) tid(37c) 80070002 The system cannot find the file specified.
    CallContext:[\Bridge_ProcessMessage\VmHostedContainer_ExecuteProcess] 
 Provider: 00000000-0000-0000-0000-000000000000] extra info: {"CommandLine":"powershell -NoProfile -NoLogo -InputFormat text -OutputFormat text -NonInteractive -ExecutionPolicy Bypass -Command -","User":"ContainerUser","WorkingDirectory":"C:\\","Environment"

当我查看日志时,它说它试图运行我从未指定的作业的 step_script 阶段,它试图运行 powershell。为什么会发生这种情况,我该如何摆脱它?我认为 dotnet:latest 中没有 powershell,因为构建不需要它。

标签: dockergitlab-cigitlab-ci-runner

解决方案


首先,最好使用固定标签而不是移动的“ latest”:从一个构建到下一个构建,“最新”可以引用新的映像版本。

mcr.microsoft.com/dotnet/core/sdk:3.第二次尝试使用特定的 dotnet 映像,例如microsoft/dotnet:xxx:注意,尽管他们可能使用 Powershell,如他们的 Dockerfile中所示

尝试 GitLab 之外的.Dotnet 示例之一,看看您是否可以手动使其工作,然后将其包含在您的gitlab-ci.yml.

注意:从gitlab-org/gitlab-runnerissue 26418 开始step_script将等同于build_script.


推荐阅读