Jenkins无法使用https和SSL连接SonarQube

时间:2019-04-15 06:34:51

标签: jenkins openssl sonarqube sonarscanner

环境详细信息

 <thead>
  <tr>
    @can('delete',app($dataType->model_name))
    <th>
      <input type="checkbox" class="select_all">
    </th>
    @endcan
    @foreach($dataType->browseRows as $row)
    <th>
      @if ($isServerSide)
      <a href="{{ $row->sortByUrl($orderBy, $sortOrder) }}">
        @endif
        {{ $row->display_name }}
        @if ($isServerSide)
        @if ($row->isCurrentSortField($orderBy))
        @if ($sortOrder == 'asc')
        <i class="voyager-angle-up pull-right"></i>
        @else
        <i class="voyager-angle-down pull-right"></i>
        @endif
        @endif
      </a>
      @endif
    </th>
    @endforeach
    <th class="actions text-right">{{ __('voyager::generic.actions') }}</th>
  </tr>
</thead>

在Sonarqube服务器上,我使用以下命令创建了自签名证书。

SonarQube – Version - 6.7.6(LTS)
OS – CentOS – 7.6
Protocol- Https
Certificate: SSL – Self Signed.
Jenkins: 2.164.1
Sonar Scanner Version - 3.3.0.1492
Nginx configured for reverse proxy.

从詹金斯(Jenkins)分析代码出现以下错误时

openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /root/ssl-key/ sonarqube.key -out /root/ssl-key/sonarqube.crt

我的声纳服务器(11:30:33.957 ERROR: SonarQube server [https://sonarqube/sonar] can not be reached 11:30:33.958 INFO: ------------------------------------------------------------------------ 11:30:33.958 INFO: EXECUTION FAILURE 11:30:33.958 INFO: ------------------------------------------------------------------------ 11:30:33.959 INFO: Total time: 0.487s 11:30:33.987 INFO: Final Memory: 4M/121M 11:30:33.987 INFO: ------------------------------------------------------------------------ 11:30:33.988 ERROR: Error during SonarQube Scanner execution org.sonarsource.scanner.api.internal.ScannerException: Unable to execute SonarQube at org.sonarsource.scanner.api.internal.IsolatedLauncherFactory$1.run(IsolatedLauncherFactory.java:84) at org.sonarsource.scanner.api.internal.IsolatedLauncherFactory$1.run(IsolatedLauncherFactory.java:71) at java.security.AccessController.doPrivileged(Native Method) at org.sonarsource.scanner.api.internal.IsolatedLauncherFactory.createLauncher(IsolatedLauncherFactory.java:71) at org.sonarsource.scanner.api.internal.IsolatedLauncherFactory.createLauncher(IsolatedLauncherFactory.java:67) at org.sonarsource.scanner.api.EmbeddedScanner.doStart(EmbeddedScanner.java:218) at org.sonarsource.scanner.api.EmbeddedScanner.start(EmbeddedScanner.java:156) at org.sonarsource.scanner.cli.Main.execute(Main.java:74) at org.sonarsource.scanner.cli.Main.main(Main.java:61) Caused by: java.lang.IllegalStateException: Fail to get bootstrap index from server at org.sonarsource.scanner.api.internal.Jars.getBootstrapIndex(Jars.java:100) at org.sonarsource.scanner.api.internal.Jars.getScannerEngineFiles(Jars.java:76) at org.sonarsource.scanner.api.internal.Jars.download(Jars.java:70) at org.sonarsource.scanner.api.internal.JarDownloader.download(JarDownloader.java:39) at org.sonarsource.scanner.api.internal.IsolatedLauncherFactory$1.run(IsolatedLauncherFactory.java:75) ... 8 more Caused by: javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target 中有以下两个文件,后来我将这两个文件复制到了Jenkins服务器中,并且执行时仍然出现相同的错误。

1 个答案:

答案 0 :(得分:0)

由于Jenkins在Java上运行,因此您需要使Java信任您的自签名证书。为此,您可以使用Java的keytool命令将Sonarqube服务器中的证书(而非密钥)导入Java的cacerts信任库中:

keytool -import -trustcacerts -keystore $JAVA_HOME/jre/lib/security/cacerts -storepass changeit -alias SonarQube -import -file sonarqube.crt

或者,如果您具有对Jenkins主机的基于GUI的访问权限,则可以使用Portecle之类的工具来执行导入。