由于找不到命令,SonarQube 扫描仪在 Jenkins 管道中失败 [英] SonarQube Scanner fails in a Jenkins pipeline due to command not found

查看:42
本文介绍了由于找不到命令,SonarQube 扫描仪在 Jenkins 管道中失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从 Jenkins 管道运行 SonarQube Scanner,我按照文档进行操作.

I'd like to run SonarQube Scanner from a Jenkins pipeline and I followed the documentation.

关于错误,似乎存在扫描仪但未找到某些命令.我的 jenkins 实例在 docker 中运行.

Regarding the error, it seems that the scanner is present but some commands are not found. My jenkins instance runs in a docker.

Jenkins 版本:2.46.1

Jenkins version : 2.46.1

SonarQube 扫描仪:2.6.1

SonarQube Scanner : 2.6.1

+ /var/lib/jenkins/tools/hudson.plugins.sonar.SonarRunnerInstallation/SonarQube_Scanner/bin/sonar-scanner
/var/lib/jenkins/tools/hudson.plugins.sonar.SonarRunnerInstallation/SonarQube_Scanner/bin/sonar-scanner: line 56: which: command not found
/var/lib/jenkins/tools/hudson.plugins.sonar.SonarRunnerInstallation/SonarQube_Scanner/bin/sonar-scanner: line 66: exec: : not found

推荐答案

sonar-scanner脚本中有这个块

if [ -n "$JAVA_HOME" ]
then
  java_cmd="$JAVA_HOME/bin/java"
else
  java_cmd="$(which java)"
fi

鉴于我的 JAVA_HOME 未设置,名为 which 的脚本和该命令未安装在我的容器中.

And given that my JAVA_HOME was unset, the script called which and the command is not installed inside my container.

作为一种解决方法,我设置了环境变量 JAVA_HOME.

As a workaround, I set the env variable JAVA_HOME.

这篇关于由于找不到命令,SonarQube 扫描仪在 Jenkins 管道中失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆