我正在尝试通过jenkins管道脚本构建声纳,在构建过程中我遇到无法到达本地主机9000的错误。
15:30:58.225 ERROR: SonarQube server [http://localhost:9000] can not be reached
15:30:58.225 INFO: ------------------------------------------------------------------------
15:30:58.226 INFO: EXECUTION FAILURE
15:30:58.226 INFO: ------------------------------------------------------------------------
15:30:58.227 INFO: Total time: 0.603s
15:30:58.243 INFO: Final Memory: 3M/121M
15:30:58.245 INFO: ------------------------------------------------------------------------
15:30:58.246 ERROR: Error during SonarQube Scanner execution
org.sonarsource.scanner.api.internal.ScannerException: Unable to execute SonarQube
at org.sonarsource.scanner.api.internal.IsolatedLauncherFactory.lambda$createLauncher$0(IsolatedLauncherFactory.java:85)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at org.sonarsource.scanner.api.internal.IsolatedLauncherFactory.createLauncher(IsolatedLauncherFactory.java:74)
at org.sonarsource.scanner.api.internal.IsolatedLauncherFactory.createLauncher(IsolatedLauncherFactory.java:70)
at org.sonarsource.scanner.api.EmbeddedScanner.doStart(EmbeddedScanner.java:185)
at org.sonarsource.scanner.api.EmbeddedScanner.start(EmbeddedScanner.java:123)
at org.sonarsource.scanner.cli.Main.execute(Main.java:73)
at org.sonarsource.scanner.cli.Main.main(Main.java:61)
Caused by: java.lang.IllegalStateException: Fail to get bootstrap index from server
at
Caused by: java.net.ConnectException: Failed to connect to localhost/127.0.0.1:9000
注意:我可以在y浏览器中访问我的localhost声纳9000,而且在上述jenkins输出中,有一个构建点网址(如localhost:9000)也可以从jenkins日志中访问,但在该行的末尾就像是无法到达主机127.0.0.1的一行
vi /etc/hosts
127.0.0.1 sonarqube
def label = "worker-${UUID.randomUUID().toString()}"
podTemplate(label: label, containers: [
containerTemplate(name: 'nodejs', image: 'node:10-buster', ttyEnabled: true, command: 'cat'),
containerTemplate(name: 'docker', image: 'docker:1.12.6', command: 'cat', ttyEnabled: true),
containerTemplate(name: 'sonarqube', image: 'sonarsource/sonar-scanner-cli:latest', command: 'cat', ttyEnabled: true),
containerTemplate(name: 'kubectl', image: 'lachlanevenson/k8s-kubectl:v1.8.3', command: 'cat', ttyEnabled: true)
],
volumes: [
hostPathVolume(mountPath: '/var/run/docker.sock', hostPath: '/var/run/docker.sock'),
]) {
node(label) {
def myRepo = checkout scm
def gitCommit = myRepo.GIT_COMMIT
def gitBranch = myRepo.GIT_BRANCH
def shortGitCommit = "${gitCommit[0..10]}"
def previousGitCommit = sh(script: "git rev-parse ${gitCommit}~", returnStdout: true)
stage('sonar-scanner') {
container('sonarqube') {
sh "/opt/sonar-scanner/bin/sonar-scanner -X -Dsonar.host.url=http://localhost:9000 -Dsonar.login=admin"
}
}
}
}
答案 0 :(得分:0)
由于您的Jenkins如注释中所述在docker容器中运行构建,因此解决方案是使用IP地址或本地DNS名称从构建脚本中访问sonarqube,因为localhost无法解析为主机在Docker容器中的机器。
答案 1 :(得分:0)
我认为这与代理有关。 如果您正在代理后面运行声纳生命周期,请在Maven .m2 / settings.xml中注释代理指令块
例如。
<!-
->