我正在使用.net核心3.1,为此,我创建了一个坞文件,其中还包含一些工具,如nodejs、openjdk-11等。这个停靠文件已经被推入AWS ECR (坞映像基于linux容器)。
最重要的是,我一直在用声纳-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
根据上述错误,声纳扫描仪的结束命令是停止处理.1.码头文件:
#
# 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. Jenkins文件:
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
}
}
尽管我在码头映像中设置了路径和JAVA_HOME。
我试过了所有的解决方案,但没有对我有效。有人能指点我吗?
谢谢
发布于 2020-06-26 03:47:30
虽然报告是JAVA_HOME,但实际使用的是声纳扫描仪中的jre,这需要授权:
chmod 755 ...sonar-scanner-4.3.0.2102-linux/jre/bin/java
https://stackoverflow.com/questions/62134303
复制相似问题