admin管理员组

文章数量:1313146

I have a Visual Studio .NET project that is engaged to an Azure project, and the pipeline build is configured within a container like below:

stages:
- stage: buildStage
   displayName: 'Build'
   jobs:
     - job: XXXXX
       displayName: 'XXXX'
       pool:
          name: XXXXX
          container:
              image: XXXX
          workspace:
              clean: all
     .........

It contains a SonarQubePrepare@6 task likes below:

- task: SonarQubePrepare@6
    displayName: 'SonarQube prepare'
    inputs:
        SonarQube: 'SonarQube-$(System.TeamProject)'
        scannerMode: 'CLI'
        configMode: 'file'
        projectKey: 'XXXX'
     .........

However the pipeline builds were always failed with the below error message:

[error][SQ] API GET '/api/server/version' failed, error is request to failed, reason: getaddrinfo ENOTFOUND xxx-sonarqube.azurewebsites.

Someone advised that it is because proxy setting is NOT configured for the container to connect to the SonarQube server.

I am not sure what is the root cause of the above issue. Could anyone please advise? Thanks a lot!

New update on 17 Feb 2025 --------------------

Thanks for all the replies. I have combined all the suggestions and am very close to the final, but just a gap I think.

First, within the container the task can definitely retrieve the proxy setting of the agent host. I can see on the log that the proxy server and port are all displayed.

Then, after importing two .cer certificate files using the Import-Certificate PS command, the task can definitely connect to the Sonarqube server via the proxy. The task uses the invoke-webrequest PS command and successfully get the version number from the link. Hence that is an issue regarding trusted certificates.

HOWEVER, the SonarQubePrepare is still failed with the same error message as my first attempt. It seems to be a problem regarding certificates. I have tried many times but still can't find a manner to let the SonarQubePrepare task refering to those two .cer certificate files.

Any suggestions?

I have a Visual Studio .NET project that is engaged to an Azure project, and the pipeline build is configured within a container like below:

stages:
- stage: buildStage
   displayName: 'Build'
   jobs:
     - job: XXXXX
       displayName: 'XXXX'
       pool:
          name: XXXXX
          container:
              image: XXXX
          workspace:
              clean: all
     .........

It contains a SonarQubePrepare@6 task likes below:

- task: SonarQubePrepare@6
    displayName: 'SonarQube prepare'
    inputs:
        SonarQube: 'SonarQube-$(System.TeamProject)'
        scannerMode: 'CLI'
        configMode: 'file'
        projectKey: 'XXXX'
     .........

However the pipeline builds were always failed with the below error message:

[error][SQ] API GET '/api/server/version' failed, error is request to https://xxx-sonarqube.azurewebsites/api/server/version failed, reason: getaddrinfo ENOTFOUND xxx-sonarqube.azurewebsites.

Someone advised that it is because proxy setting is NOT configured for the container to connect to the SonarQube server.

I am not sure what is the root cause of the above issue. Could anyone please advise? Thanks a lot!

New update on 17 Feb 2025 --------------------

Thanks for all the replies. I have combined all the suggestions and am very close to the final, but just a gap I think.

First, within the container the task can definitely retrieve the proxy setting of the agent host. I can see on the log that the proxy server and port are all displayed.

Then, after importing two .cer certificate files using the Import-Certificate PS command, the task can definitely connect to the Sonarqube server via the proxy. The task uses the invoke-webrequest PS command and successfully get the version number from the https://xxx-sonarqube.azurewebsites/api/server/version link. Hence that is an issue regarding trusted certificates.

HOWEVER, the SonarQubePrepare is still failed with the same error message as my first attempt. It seems to be a problem regarding certificates. I have tried many times but still can't find a manner to let the SonarQubePrepare task refering to those two .cer certificate files.

Any suggestions?

Share Improve this question edited Feb 17 at 11:59 John Z asked Jan 31 at 7:04 John ZJohn Z 112 bronze badges 5
  • does the container has internet access? try to run a ps job to ping or lookup xxx-sonarqube.azurewebsites – qkfang Commented Jan 31 at 10:41
  • @johnz, you should fix the yaml definition, container should be aligned with pool, and check the network setting on your agent machine, make sure the container can access the website, please check the details below, thanks. – wade zhou - MSFT Commented Feb 10 at 2:03
  • Hi, I have made a couple of tests, and there are something intestesting: 1. The agent machine can definitely connect to the sonarqube website via the proxy server. I created a pipeline job without using containers, and the job can successfully run the SonarQubePrepare task. 2. If the job is run within the container, then the job can connect to the proxy server BUT can't connect to the SonarQube server via the proxy. I did run PS scripts to connect the the proxy server and its 8080 port, it was passed. However the attempt to connecting to the Sonarqube server via the proxy was failed. – John Z Commented Feb 11 at 6:06
  • So the conclusion of my tests is: If the Azure pipeline job is running on the agent WITHOUT using a container, then all are good. The proxy server can be connected, and the Sonarqube server can be connected via the proxy. If the Azure pipeline job is running withing a container, then it failed to connect to the Sonarqube server via proxy, although the the proxy server itself can be conncted to. – John Z Commented Feb 11 at 6:12
  • @JohnZ, as per the sonar doc for CICD which agent behind proxy, try to add extraProperties for the prepare task, I will add detail below. – wade zhou - MSFT Commented Feb 12 at 2:34
Add a comment  | 

1 Answer 1

Reset to default 0

[error][SQ] API GET '/api/server/version' failed, error is request to https://xxx-sonarqube.azurewebsites/api/server/version failed, reason: getaddrinfo ENOTFOUND xxx-sonarqube.azurewebsites.

The error indicates it's not able to connect the site.

Firstly, to use the container, you should put it align with pool, it's same level. It won't work if you put it inside the pool definition.

stages:
- stage: buildStage
  displayName: 'Build'
  jobs:
    - job: testjob
      displayName: 'testjob'
      pool:
          name: 'xxxxx'
      container: mcr.microsoft/windows/servercore:ltsc2019    # align with pool
      workspace:                                    # align in same way
        clean: all

You can refer to the official doc sample for the details.

It will have the step for container initialization as below, it pulls the container to the agent machine, the job tasks are executed on the container.

In addition, you are using name:XXX for pool, which should be a self-hosted agent, you need to make sure the agent machine is able to access the website xxx-sonarqube.azurewebsites.

Please Check the network and DNS resolution in agent machine, so that the container could be able to access the website.

Edit:

As per the sonar cloud doc for CICD when host is behind proxy, you need to set parameters.

Try to add extraProperties for the prepare task. Or you need to add the environment variables mentioned in doc which is equal.

- task: SonarCloudPrepare@3
  displayName: 'Prepare analysis configuration'
  inputs:
    SonarCloud: 'SonarConn1'
    ...
    extraProperties: |
      # Additional properties that will be passed to the scanner, 
      # Put one key=value per line, example:
      # sonar.exclusions=**/*.bin
      sonar.scanner.proxyHost=proxyserver
      sonar.scanner.proxyPort=port
      sonar.scanner.proxyUser=username
      sonar.scanner.proxyPassword=password

本文标签: Connect to Sonarqube from an Azure pipeline build within a containerStack Overflow