Dotnet Sonarscanner在Docker建造过程中失败
我正在为Azure DevOps中的.NET Core应用程序内的Docker容器内的声纳扫描仪实现解决方案。
目前,安装的声纹质量是在AKS群集中的Sonarqube名称空间上,我们的DOT Net应用程序在同一群集中以不同的名称空间进行了容器。我正在努力处理以下错误:临时分析目录(通常是.sonarqube)不存在。 “开始”步骤可能没有执行。是否有任何实现这种逻辑的示例或工作码头文件?我试图按照此博客文章,但结果是相同的。
这是我的Dockerfile:
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
WORKDIR /app
EXPOSE 80
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
RUN apt-get update && apt-get install -y openjdk-11-jdk
RUN dotnet tool install --global dotnet-sonarscanner
RUN dotnet tool install --global dotnet-reportgenerator-globaltool
RUN dotnet tool install --global coverlet.console
## Set the dotnet tools folder in the PATH env variable
ENV PATH="$PATH:/root/.dotnet/tools"
## Start scanner
RUN dotnet sonarscanner begin \
/k:"my-token" \
/o:"my-org" \
/d:sonar.host.url="sonar-host" \
/d:sonar.login="sonar-token" \
/d:sonar.cs.opencover.reportsPaths=/coverage.opencover.xml
COPY my-project/*.csproj ./my-project/
COPY . .
WORKDIR /src/my-project
RUN dotnet restore
RUN dotnet build -c Release -o /app/build --no-restore
RUN dotnet test /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:CoverletOutput="/coverage"
## Stop scanner
RUN dotnet sonarscanner end /d:sonar.login="sonar-token"
FROM build AS publish
WORKDIR /src/my-project
RUN dotnet publish -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "my-project.dll"]
I am working on implementing a solution for a sonar scanner inside a docker container for the .net core application in azure DevOps.
Currently, the sonarqube installed was on a sonarqube namespace in the AKS cluster and our dot net application is containerized in a different namespace in the same cluster. I'm struggling with the following error: The temporary analysis directory (usually .sonarqube) doesn't exist. The "begin" step was probably not executed. Is there any sample or working Docker file which implements this type of logic? I tried to follow the steps described in this blog post but the result is the same.
Here is my Dockerfile:
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
WORKDIR /app
EXPOSE 80
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
RUN apt-get update && apt-get install -y openjdk-11-jdk
RUN dotnet tool install --global dotnet-sonarscanner
RUN dotnet tool install --global dotnet-reportgenerator-globaltool
RUN dotnet tool install --global coverlet.console
## Set the dotnet tools folder in the PATH env variable
ENV PATH="$PATH:/root/.dotnet/tools"
## Start scanner
RUN dotnet sonarscanner begin \
/k:"my-token" \
/o:"my-org" \
/d:sonar.host.url="sonar-host" \
/d:sonar.login="sonar-token" \
/d:sonar.cs.opencover.reportsPaths=/coverage.opencover.xml
COPY my-project/*.csproj ./my-project/
COPY . .
WORKDIR /src/my-project
RUN dotnet restore
RUN dotnet build -c Release -o /app/build --no-restore
RUN dotnet test /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:CoverletOutput="/coverage"
## Stop scanner
RUN dotnet sonarscanner end /d:sonar.login="sonar-token"
FROM build AS publish
WORKDIR /src/my-project
RUN dotnet publish -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "my-project.dll"]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
找到以下内容:
请注意Dockerfile中的WorkDir语句,并确保所有这3个命令在同一目录中执行。
Found this: https://community.sonarsource.com/t/sonarqube-is-not-showing-msbuild-analysis/44455/7
This is what did the trick for me:
Be careful with the WORKDIR statements in your Dockerfile and ensure all those 3 commands are executed within the same directory.
我相信您的问题可能正在运行
dotnet Restore
sonarscanner begin
。如果您重新安排这些步骤,则可以。I believe your issue may be running
dotnet restore
after thesonarscanner begin
. If you re-arrange those steps, you should be OK.通过在本地安装dotnet-sonarscanner来工作。在Dockerfile中使用以下命令
Worked by installing dotnet-sonarscanner locally. Use the below command in the dockerfile