Jenkins git插件自签名证书

我目前正在尝试让Jenkins构建托管在GitHub企业存储库中的项目。我们正在对GitHub服务器使用自签名证书,这会导致一些问题。

这些我能解决的大多数问题:

获取PEM格式的证书,并教git使用.config文件查找信息:

[http "https://github.*******************.com"]

sslCAInfo = "path\\to\\selvSignedCerts\\fileName.pem"

sslCAPath = "path\\to\\selvSignedCerts\\"

sslVerify = true

将证书信息添加到java cacerts密钥库中:

keytool -import -trustcacerts -alias myAlias 

-keystore "%JenkinsInstallDir\jre\lib\security\cacerts"

-file "myCertsInfo.pem"

将信息导入密钥库后重新启动Jenkins终于成功了,因此我能够在

Manage Jenkins- > Configure System-> GitHub Enterprise Servers-> API

Endpoint中配置GitHub Enterprise服务器

由于以下原因,以前无法进行此配置:

SSL certificate problem: self signed certificate in certificate chain

现在,我的git命令行很高兴,Jenkins中的GitHub插件很高兴,这意味着Jenkins本身很高兴,但是git-client插件显然不满意。

我已经在jenkins中创建了 的管道文件 *

该作业能够执行检出,它识别两个分支,并在每个分支中找到对应的Jenkinsfile。它还使用Jenkinsfile配置为每个分支自动创建一个新作业。

jenkinsfile当前看起来像这样:

#!/usr/bin/env groovy

pipeline {

agent any

stages {

stage('Scan for new jobs') {

steps {

echo 'Scanning...'

}

}

stage('Build') {

steps {

echo 'Build'

}

}

}

}

现在,管道中的第一步是隐式scm签出。这将失败,输出如下所示:

14:01:27 Connecting to https://github.*********.com/api/v3 using <userId>/******

Obtained Jenkinsfile from <commitHash>

[Pipeline] node

Running on Jenkins in D:\****\Jenkins\****\workspace\****

[Pipeline] {

[Pipeline] stage

[Pipeline] { (Declarative: Checkout SCM)

[Pipeline] checkout

> C:\Program Files\Git\bin\git.exe rev-parse --is-inside-work-tree # timeout=10

Fetching changes from the remote Git repository

> C:\Program Files\Git\bin\git.exe config remote.origin.url https://github.****.com/***/***.git # timeout=10

Fetching without tags

Fetching upstream changes from https://github.****.com/***/***.git

> C:\Program Files\Git\bin\git.exe --version # timeout=10

using GIT_ASKPASS to set credentials

> C:\Program Files\Git\bin\git.exe fetch --no-tags --progress https://github.****.com/***/***.git +refs/heads/develop:refs/remotes/origin/develop

ERROR: Error fetching remote repo 'origin'

hudson.plugins.git.GitException: Failed to fetch from https://github.****.com/***/***.git

at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:825)

at hudson.plugins.git.GitSCM.retrieveChanges(GitSCM.java:1092)

at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1123)

at org.jenkinsci.plugins.workflow.steps.scm.SCMStep.checkout(SCMStep.java:113)

at org.jenkinsci.plugins.workflow.steps.scm.SCMStep$StepExecutionImpl.run(SCMStep.java:85)

at org.jenkinsci.plugins.workflow.steps.scm.SCMStep$StepExecutionImpl.run(SCMStep.java:75)

at org.jenkinsci.plugins.workflow.steps.AbstractSynchronousNonBlockingStepExecution$1$1.call(AbstractSynchronousNonBlockingStepExecution.java:47)

at hudson.security.ACL.impersonate(ACL.java:260)

at org.jenkinsci.plugins.workflow.steps.AbstractSynchronousNonBlockingStepExecution$1.run(AbstractSynchronousNonBlockingStepExecution.java:44)

at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)

at java.util.concurrent.FutureTask.run(Unknown Source)

at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)

at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)

at java.lang.Thread.run(Unknown Source)

Caused by: hudson.plugins.git.GitException: Command "C:\Program Files\Git\bin\git.exe fetch --no-tags --progress https://github.****.com/***/***.git +refs/heads/develop:refs/remotes/origin/develop" returned status code 128:

stdout:

stderr: fatal: unable to access 'https://github.****.com/***/***.git/': SSL certificate problem: self signed certificate in certificate chain

at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:1970)

at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:1689)

at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.access$300(CliGitAPIImpl.java:71)

at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$1.execute(CliGitAPIImpl.java:380)

at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:823)

... 13 more

[Pipeline] }

[Pipeline] // stage

[Pipeline] }

[Pipeline] // node

[Pipeline] End of Pipeline

因此错误再次出现:

stderr: fatal: unable to access 'https://github.****.com/***/***.git/': SSL certificate problem: self signed certificate in certificate chain

现在看来,git-client插件(或git插件?)似乎位于

的密钥库之外的其他地方,并且似乎也不关心 文件。

现在我的问题是,此插件将在哪里寻找有效的证书?还是我没有得到什么?

所有针对此问题或类似问题的研究都导致将证书添加到Java密钥库中,而我已经这样做了。我没有找到其他指向正确方向的信息。大多数情况下,我想知道为什么

GitHub Organizations 作业可以很好地处理存储库,检测所有分支,检出并处理 Jenkinsfile

和其他作业(我还手动创建了一个freestyle作业,以检查它是否可以检出存储库-具有相同否定结果)由于 自签名证书 问题仍无法访问该回购…

运行Jenkins)

Windows 7 x64

git版本1.9.4.msysgit.0

Jenkins版本:2.73.2

Java JRE:1.8.0_144-b01

插件:

git 3.6.3

git-client 2.6.0

git-server 1.7

github 1.28.1

github-api 1.90

回答:

好的,我找到了答案。 进行救援!

使用进程监视器,我可以看到,该 正在读一本gitconfig文件,同时建立我的小自由泳项目。

现在,令我惊讶的是,它 读取用户目录(也就是全局配置)中的 .gitconfig ,也

读取系统下的一个(也就是系统配置),而是读取了位于以下位置的.gitconfig文件:

C:\Program Files\Git\mingw64\etc\.gitconfig

该文件的原始内容如下:

[http]

sslCAInfo = C:/Program Files/Git/mingw64/ssl/certs/ca-bundle.crt

sslBackend = openssl

[diff "astextplain"]

textconv = astextplain

[credential]

helper = manager

在添加了如上所示的有关我的自签名证书信息的信息之后,现在的内容是:

[http]

sslCAInfo = C:/Program Files/Git/mingw64/ssl/certs/ca-bundle.crt

sslBackend = openssl

##################################

# Self Signed Server Certificate

[http "https://github.****.com"]

sslCAInfo = "path\\to\\selvSignedCerts\\fileName.pem"

sslCAPath = "path\\to\\selvSignedCerts\\"

sslVerify = true

[diff "astextplain"]

textconv = astextplain

[credential]

helper = manager

瞧-自由式作业和Jenkinsfile定义的自动生成的作业可以成功检出存储库并成功构建。

希望这可以帮助其他使用自签名证书的人度过难关。

停止使用自签名证书!买一个正式的会便宜一些!(必须与我们的IT部门联系…)

以上是 Jenkins git插件自签名证书 的全部内容, 来源链接: utcz.com/qa/397919.html

回到顶部