连接到Gitlab连接到Sonar时的连接拒绝

发布于 2025-02-07 17:10:47 字数 3296 浏览 2 评论 0原文

我在配置Sonarqube配置GitLab管道时面临问题。 在localhot上运行的GitLab端口80和声纳在localhost port 9000 在同一本地Linux机器中。

如果我正在从本地Linux终端执行命令与Sonar连接,则可以正常工作,但是在Gitlab管道中抛出错误的东西。

命令从终端和管道执行:

dotnet sonarscanner begin /k:“ project” /d:sonar.login = username /d:sonar.password = password = password = password = password /d:sonar.host.url = http://127.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0 .0.1:9000

执行上述命令后,其工作正常,但在Gitlab管道中会遇到Bellow错误。

无法请求并解析'http://127.0.0.1:1:9000/api/server/version':连接拒绝

stages:
  - sonar

Gitlab Pipeline:
sonarqube-check:
  stage: sonar
  image: mcr.microsoft.com/dotnet/sdk:6.0
  variables:
    SONAR_USER_HOME: "${CI_PROJECT_DIR}/.sonar"
 task cache
    GIT_DEPTH: "0"
  cache:
    key: "${CI_JOB_NAME}"
    paths:
      - .sonar/cache
  script: 
      - "apt-get update"
      - "apt-get install --yes openjdk-11-jre"
      - "dotnet tool install --global dotnet-sonarscanner"
      - "export PATH=\"$PATH:$HOME/.dotnet/tools\""
      - "dotnet sonarscanner begin /k:"trukkerfinops" /d:sonar.login=username /d:sonar.password=password /d:sonar.host.url=http://127.0.0.1:9000"
      - "dotnet build"
      - "dotnet sonarscanner end /d:sonar.login=\"$SONAR_TOKEN\""
  allow_failure: true
  only:
    - main

[[runners]]
  name = "devops"
  url = "http://localhost/"
  token = "token"
  executor = "docker"
  clone_url = "http://machine_ip"
  [runners.custom_build_dir]
  [runners.cache]
    [runners.cache.s3]
    [runners.cache.gcs]
    [runners.cache.azure]
  [runners.docker]
    tls_verify = false
    image = "dind"
    privileged = true
    disable_entrypoint_overwrite = false
    oom_kill_disable = false
    disable_cache = false
    volumes = ["/var/run/docker.sock:/var/run/docker.sock", "/cache"]
    shm_size = 0

127.0.0.1:9000

$ dotnet sonarscanner begin /k:"project" /d:sonar.login=username /d:sonar.password=password /d:sonar.host.url=http://localhost:9000
SonarScanner for MSBuild 5.6
Using the .NET Core version of the Scanner for MSBuild
Pre-processing started.
Preparing working directories...
13:52:04.682  Updating build integration targets...
13:52:04.781  Failed to request and parse 'http://localhost:9000/api/server/version': Cannot assign requested address (localhost:9000)
Unhandled exception. System.Net.Http.HttpRequestException: Cannot assign requested address (localhost:9000)
 ---> System.Net.Sockets.SocketException (99): Cannot assign requested address
   at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ThrowException(SocketError error, CancellationToken cancellationToken)
   at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 token)
   at System.Net.Sockets.Socket.<ConnectAsync>g__WaitForConnectWithCancellation|277_0(AwaitableSocketAsyncEventArgs saea, ValueTask connectTask, CancellationToken cancellationToken)
   at System.Net.Http.HttpConnectionPool.ConnectToTcpHostAsync(String host, Int32 port, HttpRequestMessage initialRequest, Boolean async, CancellationToken cancellationToken)
   --- End of inner exception stack trace ---

) Google的选项,但直到还没有运气

I am facing issue while configuring Gitlab pipeline with SonarQube.
Gitlab running on localhot port 80 and Sonar running on localhost port 9000 in the same local linux machine.

If I am executing command from local linux terminal to connect with Sonar, it works fine, but same thing throwing error in Gitlab pipeline.

Command to execute from Terminal and pipeline:

dotnet sonarscanner begin /k:"project" /d:sonar.login=username /d:sonar.password=password /d:sonar.host.url=http://127.0.0.1:9000

After executing above command it work fine but in Gitlab pipeline getting bellow error.

Failed to request and parse 'http://127.0.0.1:9000/api/server/version': Connection refused (127.0.0.1:9000)

stages:
  - sonar

Gitlab Pipeline:
sonarqube-check:
  stage: sonar
  image: mcr.microsoft.com/dotnet/sdk:6.0
  variables:
    SONAR_USER_HOME: "${CI_PROJECT_DIR}/.sonar"
 task cache
    GIT_DEPTH: "0"
  cache:
    key: "${CI_JOB_NAME}"
    paths:
      - .sonar/cache
  script: 
      - "apt-get update"
      - "apt-get install --yes openjdk-11-jre"
      - "dotnet tool install --global dotnet-sonarscanner"
      - "export PATH=\"$PATH:$HOME/.dotnet/tools\""
      - "dotnet sonarscanner begin /k:"trukkerfinops" /d:sonar.login=username /d:sonar.password=password /d:sonar.host.url=http://127.0.0.1:9000"
      - "dotnet build"
      - "dotnet sonarscanner end /d:sonar.login=\"$SONAR_TOKEN\""
  allow_failure: true
  only:
    - main

Runner configuration:

[[runners]]
  name = "devops"
  url = "http://localhost/"
  token = "token"
  executor = "docker"
  clone_url = "http://machine_ip"
  [runners.custom_build_dir]
  [runners.cache]
    [runners.cache.s3]
    [runners.cache.gcs]
    [runners.cache.azure]
  [runners.docker]
    tls_verify = false
    image = "dind"
    privileged = true
    disable_entrypoint_overwrite = false
    oom_kill_disable = false
    disable_cache = false
    volumes = ["/var/run/docker.sock:/var/run/docker.sock", "/cache"]
    shm_size = 0

Console log:

$ dotnet sonarscanner begin /k:"project" /d:sonar.login=username /d:sonar.password=password /d:sonar.host.url=http://localhost:9000
SonarScanner for MSBuild 5.6
Using the .NET Core version of the Scanner for MSBuild
Pre-processing started.
Preparing working directories...
13:52:04.682  Updating build integration targets...
13:52:04.781  Failed to request and parse 'http://localhost:9000/api/server/version': Cannot assign requested address (localhost:9000)
Unhandled exception. System.Net.Http.HttpRequestException: Cannot assign requested address (localhost:9000)
 ---> System.Net.Sockets.SocketException (99): Cannot assign requested address
   at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ThrowException(SocketError error, CancellationToken cancellationToken)
   at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 token)
   at System.Net.Sockets.Socket.<ConnectAsync>g__WaitForConnectWithCancellation|277_0(AwaitableSocketAsyncEventArgs saea, ValueTask connectTask, CancellationToken cancellationToken)
   at System.Net.Http.HttpConnectionPool.ConnectToTcpHostAsync(String host, Int32 port, HttpRequestMessage initialRequest, Boolean async, CancellationToken cancellationToken)
   --- End of inner exception stack trace ---

I have tried many more options from google but no luck till yet

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

囍笑 2025-02-14 17:10:47

要提出HTTP请求

To make HTTP request please add --net=host to your code

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文