我正在使用.net core 3.1,为此,我创建了一个docker文件,其中也包含一些针对Jenkins的工具,例如nodejs,openjdk-11等。此docker文件已被推送到AWS ECR(docker映像基于linux容器)。
主要的事情是,我一直在与詹金斯一起使用声纳Qube。当在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
根据上述错误,声纳扫描仪的结束命令正在停止处理。 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。
我为此尝试了所有解决方案,但对我没有任何帮助。 有人可以为此指导我吗?
谢谢
答案 0 :(得分:0)
虽然报告是JAVA_HOME,但实际使用的是声纳扫描仪中的jre,需要授权:
chmod 755 ...sonar-scanner-4.3.0.2102-linux/jre/bin/java