Devops Quality Gate stuck waiting for Sonar Publish

image

I am having the same issue as Publishing code analysis results to AzureDevops from docker.

The issue is that the analysis runs in docker, but the gate in Azure Devops never completes. Here is my yml for Azure Dev ops

trigger:
  branches:
    include:
    - refs/heads/QA

pool:
  vmImage: 'ubuntu-latest' 

steps:
- checkout: self
  persistCredentials: True
- task: Docker@2
  displayName: Build an image
  inputs:
    repository: [Redacted]
    Dockerfile: Dockerfile
    arguements: '--build-arg sonar.pullrequest.vsts.project=$(System.TeamProject) --build-arg sonar.pullrequest.vsts.repository=$(Build.Repository.Name) --build-arg sonar.pullrequest.vsts.instanceUrl=$(System.CollectionUri)'
    command: build 

Here is my dockfile

#######################################################
# Step 1: Build the application in a container        #
#######################################################
# Download the official ASP.NET Core SDK image
# to build the project while creating the docker image
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build

ARG SONAR_OGRANIZAION_KEY=[Redacted]
ARG SONAR_PROJECT_KEY=[Redacted]
ARG SONAR_HOST_URL=https://sonarcloud.io
ARG SONAR_TOKEN=[Redacted]

WORKDIR /app

EXPOSE 80

# Install Sonar Scanner, Coverlet and Java (required for Sonar Scanner)
RUN apt-get update && apt-get install -y openjdk-17-jdk-headless
RUN dotnet tool install --global dotnet-sonarscanner
RUN dotnet tool install --global coverlet.console
ENV PATH="$PATH:/root/.dotnet/tools"

# Start Sonar Scanner
RUN dotnet sonarscanner begin \
  /k:"$SONAR_PROJECT_KEY" \
  /o:"$SONAR_OGRANIZAION_KEY" \
  /d:sonar.host.url="$SONAR_HOST_URL" \
  /d:sonar.login="$SONAR_TOKEN" \
  /d:sonar.cs.opencover.reportsPaths=/coverage.opencover.xml

# Restore NuGet packages
COPY . .
RUN dotnet restore

# Build and test the application
RUN dotnet publish --output /app/out/

RUN dotnet test \
  /p:CollectCoverage=true \
  /p:CoverletOutputFormat=opencover

# End Sonar Scanner
RUN dotnet sonarscanner end /d:sonar.login="$SONAR_TOKEN"

# Copy the rest of the files over
COPY . .

FROM mcr.microsoft.com/dotnet/aspnet:8.0
WORKDIR /app
COPY --from=build /app/out .

ENTRYPOINT ["dotnet", "DotNet.Docker.dll"]
  • ALM used: Azure DevOps
  • CI system: Azure DevOps
  • Scanner command: RUN dotnet sonarscanner end /d:sonar.login=“$SONAR_TOKEN”
  • Languages of the repository: C#
  • Error observed: Azure Devops Quality Gate Waiting Forever
1 Like

I had misspelled arguments, and not passed the variables correctly. Here is the correction:

YML:

# Charles Teague November 22, 2023

variables:
- name: DOCKER_BUILDKIT
  value: 1

trigger:
  branches:
    include:
    - refs/heads/QA

pool:
  vmImage: 'ubuntu-latest' 

steps:
- checkout: self
  persistCredentials: True
- task: Docker@2
  displayName: Build an image
  inputs:
    command: build
    repository: [Redacted]
    Dockerfile: Dockerfile
    arguments: '--build-arg PROJECT=$(System.TeamProject) --build-arg REPOSITORY=$(Build.Repository.Name) --build-arg INSTANCEURL=$(System.CollectionUri) --build-arg PULLREQUEST_ID=$(System.PullRequest.PullRequestId) --build-arg TARGET_BRANCH_NAME=$(System.PullRequest.targetBranchName) --build-arg SOURCE_BRANCH_NAME=$(System.PullRequest.SourceBranch)'

Dockerfile

#######################################################
# Step 1: Build the application in a container        #
#######################################################
# Download the official ASP.NET Core SDK image
# to build the project while creating the docker image
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build

ARG SONAR_OGRANIZAION_KEY=[Redacted]
ARG SONAR_PROJECT_KEY=[Redacted]
ARG SONAR_HOST_URL=https://sonarcloud.io
ARG SONAR_TOKEN=[Redacted]
ARG PULLREQUEST_ID
ARG SOURCE_BRANCH_NAME
ARG TARGET_BRANCH_NAME
ARG PROJECT
ARG REPOSITORY
ARG INSTANCEURL

WORKDIR /app

RUN echo ${PROJECT}
RUN echo ${REPOSITORY}
RUN echo ${INSTANCEURL}
RUN echo ${PULLREQUEST_ID}
RUN echo ${SOURCE_BRANCH_NAME}
RUN echo ${TARGET_BRANCH_NAME}
RUN echo ${SONAR_PROJECT_KEY}

EXPOSE 80

# Install Sonar Scanner, Coverlet and Java (required for Sonar Scanner)
RUN apt-get update && apt-get install -y openjdk-17-jdk-headless
RUN dotnet tool install --global dotnet-sonarscanner
RUN dotnet tool install --global coverlet.console
ENV PATH="$PATH:/root/.dotnet/tools"

# Start Sonar Scanner
RUN dotnet sonarscanner begin \
  /k:"${SONAR_PROJECT_KEY}" \
  /o:"${SONAR_OGRANIZAION_KEY}" \
  /d:sonar.host.url="${SONAR_HOST_URL}" \
  /d:sonar.login="${SONAR_TOKEN}" \
  /d:sonar.cs.opencover.reportsPaths=/coverage.opencover.xml\
  /d:sonar.pullrequest.key=${PULLREQUEST_ID}\
  /d:sonar.pullrequest.branch=${SOURCE_BRANCH_NAME}\
  /d:sonar.pullrequest.base=${TARGET_BRANCH_NAME}\
  /d:sonar.pullrequest.vsts.project=${PROJECT}\
  /d:sonar.pullrequest.vsts.repository=${REPOSITORY}\
  /d:sonar.pullrequest.vsts.instanceUrl=${INSTANCEURL}

# Restore NuGet packages
COPY . .
RUN dotnet restore

# Build and test the application
RUN dotnet publish --output /app/out/

RUN dotnet test \
  /p:CollectCoverage=true \
  /p:CoverletOutputFormat=opencover

# End Sonar Scanner
RUN dotnet sonarscanner end /d:sonar.login="${SONAR_TOKEN}"

# Copy the rest of the files over
COPY . .

FROM mcr.microsoft.com/dotnet/aspnet:6.0
WORKDIR /app
COPY --from=build /app/out .

ENTRYPOINT ["dotnet", "layoutboards.dll"]

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.