【发布时间】:2020-06-01 14:19:53
【问题描述】:
我正在使用 .net core 3.1,为此我创建了一个 docker 文件,其中还包含一些工具,如用于 Jenkins 的 nodejs、openjdk-11 等。此 docker 文件已推送到 AWS ECR(docker 镜像基于 linux 容器)。
主要的事情是,我一直在使用 sonar-qube 和 Jenkins。虽然此图像的构建作业在 Jenkins 上运行,但出现了一些奇怪的错误:
SonarScanner for MSBuild 4.9
Using the .NET Core version of the Scanner for MSBuild
Post-processing started.
Calling the SonarQube Scanner...
Could not find 'java' executable in JAVA_HOME or PATH.
The SonarQube Scanner did not complete successfully
13:59:33.157 Post-processing failed. Exit code: 1
根据上述错误,sonar-scanner 的结束命令是停止处理。 1。 Docker 文件:
#
# Start from the base image
FROM mcr.microsoft.com/dotnet/core/sdk:3.1
#
# Install dependencies
RUN apt-get -yqq update
RUN apt-get -yqq install zip
RUN apt-get -yqq install curl
RUN curl -sL https://deb.nodesource.com/setup_8.x | bash
RUN apt-get -yqq install nodejs
#RUN apt-get install -y openjdk-11-jre
RUN apt-get update && \
apt-get install -y openjdk-11-jre && \
rm -rf /var/lib/apt/lists/*
RUN dotnet tool install Amazon.Lambda.Tools --tool-path /usr/share/dotnet
RUN dotnet tool install dotnet-sonarscanner --tool-path /usr/share/dotnet
#
# Set required permissions
RUN chown 1004:sudo /usr/share/dotnet/dotnet-lambda
RUN chmod a+w /usr/bin
RUN chmod a+rwx -R /usr/share/dotnet/.store
RUN chmod o+x /usr/share/dotnet/dotnet-lambda
RUN chmod a+w /usr/share/dotnet/dotnet-sonarscanner
#
# Export paths
ENV PATH="${PATH}:/usr/share/dotnet"
ENV JAVA_HOME = /usr/lib/jvm/java-11-openjdk-amd64/bin/java
2。詹金斯档案:
def runSonarqube() {
stage('run SonarQube scan') {
sh ("dotnet tool install --global dotnet-sonarscanner")
withEnv('PATH="$PATH:/usr/share/dotnet"'){
sh('echo ${PATH}')
withSonarQubeEnv('SonarQube Server') {
sh " $HOME/.dotnet/tools/dotnet-sonarscanner begin /k:\"${projectName}\" /d:sonar.host.url=\"${sonarHostUrl}\" /d:sonar.cs.opencover.reportsPaths=\"src/Test/coverage.opencover.xml\""
sh " dotnet build "
sh " $HOME/.dotnet/tools/dotnet-sonarscanner end"
}
timeout(time: 10, unit: 'MINUTES') {
def qg = waitForQualityGate()
if (qg.status == 'ERROR') {
error "Pipeline aborted due to quality gate failure: ${qg.status}"
}
}
}
}
}
node {
def scmVars
try {
stage('notify slack') {
notifySlack()
}
stage('checkout') {
scmVars = checkout scm
}
withAWS(region: awsRegion, credentials: awsCredentialsId) {
sh "\$(aws ecr get-login --no-include-email --region ${awsRegion})"
docker.withRegistry("${imageBaseUrl}", "${imageAuthenticationCredentials}") {
sh "echo ${PATH}"
docker.image('mcr.microsoft.com/dotnet/core/sdk:3.1').inside {
withEnv(['HOME=/tmp']) {
stage('restore project dependencies') {
sh 'dotnet restore iNewsConnector.Service/iNewsConnector.Service.csproj'
}
stage('build project') {
sh 'dotnet build iNewsConnector.Service/iNewsConnector.Service.csproj --configuration Release'
}
stage('create package') {
sh "dotnet publish -f netcoreapp3.1 --nologo -o ./iNewsConnector.Service/bin/Release/netcoreapp3.1/publish"
zip zipFile: "${artifactsDir}/${packageName}", archive: true, dir: "./iNewsConnector.Service/bin/Release/netcoreapp3.1/publish"
}
stage('archive') {
// Archive the zipped package for the deployment job
archiveArtifacts artifacts: "${artifactsDir}/${packageName},git-commit.txt", fingerprint: true
}
//if(env.BRANCH_NAME == 'develop') {
// Perform SonarQube analysis
runSonarqube()
//}
}
}
}
}
currentBuild.result = 'SUCCESS'
} catch (InterruptedException e) {
// Build interupted
currentBuild.result = 'ABORTED'
throw e
} catch (e) {
// If there was an exception thrown, the build failed
currentBuild.result = 'FAILED'
throw e
} finally {
// Success or failure, always send notifications
notifySlack(currentBuild.result)
// disableDeferredWipeout makes sure that the cleanup is deterministic
cleanWs disableDeferredWipeout: true
}
}
虽然我在我的 docker 镜像中设置了 PATH 和 JAVA_HOME。
我为此尝试了所有解决方案,但对我没有任何效果。 有人可以指导我吗?
谢谢
【问题讨论】:
-
jenkins 可能会在执行时将其自己的 JAVA HOME 环境变量注入到您的容器中。因此它可能指向错误的目录。
-
是的,我指向错误的 awsCredentialsId Ita 现在已修复,谢谢。
标签: sonarqube asp.net-core-3.1 java-home