![使用 GitLab Runner 在 Docker 容器中运行 SonarQube 分析时出现“未授权”错误](https://linux22.com/image/789418/%E4%BD%BF%E7%94%A8%20GitLab%20Runner%20%E5%9C%A8%20Docker%20%E5%AE%B9%E5%99%A8%E4%B8%AD%E8%BF%90%E8%A1%8C%20SonarQube%20%E5%88%86%E6%9E%90%E6%97%B6%E5%87%BA%E7%8E%B0%E2%80%9C%E6%9C%AA%E6%8E%88%E6%9D%83%E2%80%9D%E9%94%99%E8%AF%AF.png)
我正在尝试使用 GitLab Runner 在 Docker 容器中运行 SonarQube 分析,但遇到以下错误:
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'GlobalServerSettings' defined in org.sonar.scanner.bootstrap.GlobalServerSettingsProvider: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.sonar.scanner.bootstrap.GlobalServerSettings]: Factory method 'provide' threw exception; nested exception is Not authorized. Please check the properties sonar.login and sonar.password.
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:658)
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:638)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1352)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1195)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208)
at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1391)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1311)
at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:887)
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:791)
... 70 more
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.sonar.scanner.bootstrap.GlobalServerSettings]: Factory method 'provide' threw exception; nested exception is Not authorized. Please check the properties sonar.login and sonar.password.
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185)
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:653)
... 84 more
Caused by: Not authorized. Please check the properties sonar.login and sonar.password.
Cleaning up project directory and file based variables
00:01
ERROR: Job failed: exit code 1
我的 GitLab Runner 在 Docker 容器中运行,SonarQube 也在 Docker 容器中运行。我已将 .gitlab-ci.yml 文件配置如下:
sonarqube-check:
tags:
- my-api
image:
name: sonarsource/sonar-scanner-cli:5.0
entrypoint: [""]
variables:
SONAR_USER_HOME: "${CI_PROJECT_DIR}/.sonar"
GIT_DEPTH: "0"
SONAR_TOKEN: "$SONARQUBE_TOKEN"
cache:
key: "${CI_JOB_NAME}"
paths:
- .sonar/cache
script:
- sonar-scanner -X
rules:
- if: $CI_COMMIT_BRANCH == 'main'
我的 sonar-project.properties 文件如下所示:
sonar.projectKey=my-api
sonar.qualitygate.wait=true
我已将 SonarQube 主机 URL 和令牌作为环境变量传递。有人能帮我了解导致此“未授权”错误的原因以及如何解决它吗?