Gitlab-CI无法连接到基于Windows的容器上的服务

时间:2020-04-23 07:15:55

标签: sql-server docker gitlab gitlab-ci gitlab-ci-runner

我目前正在将CI / CD管道从Bitbucket / Jenkins环境迁移到具有其他自定义gitlab-ci运行程序的托管GitLab。到目前为止,一切似乎都很好,除非涉及到服务,尤其是关于MSSQL服务器。

我已经设置了一个gitlab-ci.yml文件,其中包含一个服务和一个构建阶段作业,该作业基本上只执行一些msbuild目标。 我调用AttachDatabase目标,然后该目标内部连接到数据库并准备进行单元测试的所有内容。不幸的是,无论是否对服务进行别名,我都无法连接到数据库。

根据文档,我应该只能够在Library.Build.Database.targets中的连接字符串中使用服务中定义的别名来连接到数据库。

我已经建立了一个小的参考项目来说明问题:mssql-test

如果管道正在运行,则日志中会显示以下错误消息:

error : A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections

image: "mcr.microsoft.com/dotnet/framework/sdk:4.8-windowsservercore-ltsc2019"

variables:
  PROJ_NAME: MSSQL.Test.proj
  MSBUILD_BIN: 'C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Current\Bin\msbuild.exe'
  NUGET_BIN: 'C:\Program Files\NuGet\nuget.exe'
  ACCEPT_EULA: 'Y'
  sa_password: Unit-T3st3r

services:
  - name: advitec/mssql-server-windows-developer
    alias: mssql

attachdatabase:
  stage: build
  tags:
  - windows-1809
  - 3volutions
  - docker-windows
  cache:
    paths:
      - packages
  before_script:
  - cmd /C "$NUGET_BIN" restore .\packages.config -OutputDirectory .\packages
  allow_failure: false
  script:
  - cmd /C "$MSBUILD_BIN" "$PROJ_NAME" -t:AttachDatabase -v:Minimal "-p:Configuration=ReleaseForTesting;UniqueBuildNumber=$CI_PIPELINE_IID"

我正在运行一个自定义的Windows Gitlab运行程序(出于性能原因),位于相应的config.toml下面

Runner:
    concurrent = 1
check_interval = 0

[session_server]
  session_timeout = 1800

[[runners]]
  name = "gitlab-runner-02-windows-server-datacenter-1809"
  url = "https://gitlab.com/"
  token = "****"
  executor = "docker-windows"
  [runners.custom_build_dir]
  [runners.cache]
    [runners.cache.s3]
    [runners.cache.gcs]
  [runners.docker]
    tls_verify = false
    image = "mcr.microsoft.com/dotnet/framework/sdk:4.8-windowsservercore-ltsc2019"
    privileged = false
    disable_entrypoint_overwrite = false
    oom_kill_disable = false
    disable_cache = false
    volumes = ["c:\\cache"]
    shm_size = 0

有什么想法我想念的吗?

欢呼

0 个答案:

没有答案