1

I'm currently migrating our CI/CD pipeline from a Bitbucket/Jenkins environment to hosted GitLab with additional custom gitlab-ci runners. So far anything seems fine, except when it comes down to services, especially regarding MSSQL server.

I've setup a gitlab-ci.yml file, which contains a service and a build stage job which basically just executes some msbuild targets. I call the AttachDatabase target which then internally connects to the database and prepares anything for unittesting. Unfortunately I'm not able to connect to the database, whether I alias the service or not.

According to the documentation, I should just be able to use the alias name defined in services in my connection string found in Library.Build.Database.targets to connect to the databse.

I've setup a small reference project which ilustrates the problem: mssql-test.

If the pipeline is run the following error message is shown in the log:

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"

I'm running a custom windows Gitlab runner (just for performance reasons), below the according 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

Any ideas what I'm missing?

Cheers

Lukas
  • 156
  • 11
  • 1
    Does the docker environment have access to the mssql server which I'm assuming is running locally on the runner? (can you manually verify this as the user which the gitlab docker runner is using?) – Rekovni Apr 23 '20 at 12:26
  • Yes, since the sql server is started within a container itself this must be available see the gitlab-ci.yml file for reference – Lukas Apr 24 '20 at 10:28
  • Hey @Lukas were you able to solve this issue? – AlphaCR Jul 25 '22 at 08:42
  • Hey @Rekovni would you happen to know how I can check/ what commands to use to check on the access? – AlphaCR Jul 25 '22 at 08:43

0 Answers0