gpt4 book ai didi

jenkins - SonarQube 无法到达本地主机

转载 作者:行者123 更新时间:2023-12-05 07:15:41 25 4
gpt4 key购买 nike

我正在尝试通过 jenkins 管道脚本构建 sonarqube,在构建过程中出现无法访问本地主机 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 sonar 9000,并且在上面的 jenkins 输出中有一个构建点 url,如 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"
}
}


}

}

最佳答案

由于您的 Jenkins 在评论中提到的 docker 容器中运行构建,因此解决方案是使用 IP 地址或本地 DNS 名称从构建脚本中访问 sonarqube,因为 localhost 不会解析为主机docker 容器内的机器。

关于jenkins - SonarQube 无法到达本地主机,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59533252/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com