无法从我在 GitLab 中的测试访问活动的 mq 服务 CI/CD

Unable to access active mq service from my tests in GitLab CI/CD

首先,GitLab 免费版对服务或 docker 容器有任何限制吗? 它说我有 GitLab 企业版 11.11.0- rc1-ee

我有以下内容:

我的集成测试无法连接到活动 mq 的旋转容器。我尝试主机名“127.0.0.1”或"localhost"或“0.0.0.0”并不重要 我一直看到 ActiveMQ Connect Failed: NMSConnectionException

如果我 运行 在本地使用本地 activemq 服务器进行测试 运行ning(我只是下载了二进制文件,设置 JAVA_HOME 变量和 运行 bin/activemq开始)一切正常。

有趣的是,我 运行 在 GitLab 企业版 11.10.4-ee 中的不同管道上进行相同的测试和相同的代码,一切都进行得更快,我的测试正确执行指向"localhost" 服务器名称并使用 webcenter/activemq:5.14.3 服务。

更新 1:这是我的 .gitlab-ci.yml

#Stages
stages:
  - ci
  - pack

#Global variables
variables:
  GITLAB_RUNNER_DOTNET_CORE: mcr.microsoft.com/dotnet/core/sdk:2.2
  NUGET_REPOSITORY: $NEXUS_NUGET_REPOSITORY
  NUGET_API_KEY: $NEXUS_API_KEY
  NUGET_FOLDER_NAME: nupkgs

#Docker image
image: $GITLAB_RUNNER_DOTNET_CORE

#Jobs
ci:
  stage: ci
  services:
    - webcenter/activemq:5.14.3
  script:
    - dotnet restore --no-cache --force
    - dotnet build --configuration Release
    - dotnet vstest *Tests/bin/Release/**/*Tests.dll

pack-beta-nuget:
  stage: pack
  script:
    - export VERSION_SUFFIX=beta$CI_PIPELINE_ID
    - dotnet pack *.sln --configuration Release --output $NUGET_FOLDER_NAME --version-suffix $VERSION_SUFFIX --include-source --include-symbols -p:SymbolPackageFormat=snupkg
    - dotnet nuget push **/*.nupkg --api-key $NUGET_API_KEY --source $NUGET_REPOSITORY
  except:
    - master

pack-nuget:
  stage: pack
  script:
    - dotnet restore
    - dotnet pack *.sln --configuration Release --output $NUGET_FOLDER_NAME
    - dotnet nuget push **/*.nupkg --api-key $NUGET_API_KEY --source $NUGET_REPOSITORY
  only:
    - master

更新 2:我将以下设置与 MassTransit.ActiveMQ 5.3.2

一起使用
HostName = "localhost"; //I have tried 127.0.0.1 and 0.0.0.0 also. Same result
Username = "admin";
Password = "admin";
Port = 61616;
UseSsl = false;
AutoDelete = true;

更新 3:如果我将别名 activemq 设置为服务然后使用 HostName = "activemq" 它也不会连接。 如果我不设置任何别名而是使用自动生成的 webcenter__activemq 我遇到了同样的问题,它无法连接。

Starting test execution, please wait...
ActiveMQ Connect Failed: NMSConnectionException
ActiveMQ Connect Failed: NMSConnectionException
ActiveMQ Connect Failed: NMSConnectionException

更新 4: 我将 public 设为我的存储库。这是一个 masst运行sit 包装纸。所有 unit/integration 测试都可以通过简单地在 127.0.0.1 上拥有一个 activemq 运行ning 实例来执行。 否则(特别是对于 CI 管道)必须编辑文件 DiDrDe.MessageBus.Infra.MassTransit.IntegrationTests\TestSupport\ActiveMqTestsConstants.cs 并且必须将主机名更改为启动 CI 的 activeMq 容器的任何值。

到目前为止,我已经尝试使用 webcenter__activemq127.0.0.10.0.0.0localhostactivemq(并为服务设置相同的别名) 但运气不好

我们一直在 CI 管道中使用服务,但我们从未使用过环回地址。您提到它有效,但它可能是 shell 转轮,现在您可能正在使用 Docker 转轮。

GitLab 文档提供了 clear guidelines 如何连接到服务:

Let’s say that you need a Wordpress instance to test some API integration with your application.

You can then use for example the tutum/wordpress image in your .gitlab-ci.yml:

services:
- tutum/wordpress:latest

If you don’t specify a service alias, when the job is run, tutum/wordpress will be started and you will have access to it from your build container under two hostnames to choose from:

tutum-wordpress
tutum__wordpress

您还可以使用我在第一条评论中提到的服务别名,如文档中的 described