问题描述:
image.png

简单版解决方法:

在jenkins容器里执行git config —global http.sslVerify false
或者将此文件挂载进去
image.png

image.png

然而跑一个示例的流水线依然报该错误。原来jenkins调取的slave流水线里没有Git忽略ssl配置

通过如下命令查看jenkins/inbound-agent镜像的家目录:

  1. docker history --format {{.CreatedBy}} --no-trunc=true jenkins/inbound-agent:4.11-1-jdk11 |sed "s?/bin/sh\ -c\ \#(nop)\ ??g"|sed "s?/bin/sh\ -c?RUN?g" | tac

image.png
所以将示例的流水线加上该挂载就能跑成功了(mountPath)

  1. def label = "slave-${UUID.randomUUID().toString()}"
  2. podTemplate(label: label, containers: [
  3. containerTemplate(name: 'golang', image: 'golang:1.16.14-alpine3.14', command: 'cat', ttyEnabled: true),
  4. containerTemplate(name: 'docker', image: 'docker:latest', command: 'cat', ttyEnabled: true),
  5. containerTemplate(name: 'kubectl', image: 'cnych/kubectl', command: 'cat', ttyEnabled: true)
  6. ], serviceAccount: 'jenkins', volumes: [
  7. hostPathVolume(mountPath: '/home/jenkins/.kube', hostPath: '/root/.kube'),
  8. hostPathVolume(mountPath: '/home/jenkins/.gitconfig', hostPath: '/root/.gitconfig'),
  9. hostPathVolume(mountPath: '/var/run/docker.sock', hostPath: '/var/run/docker.sock')
  10. ]) {
  11. node(label) {
  12. def myRepo = checkout scm
  13. def gitCommit = myRepo.GIT_COMMIT
  14. def gitBranch = myRepo.GIT_BRANCH
  15. stage('单元测试') {
  16. echo "测试阶段"
  17. }
  18. stage('代码编译打包') {
  19. container('golang') {
  20. echo "代码编译打包阶段"
  21. }
  22. }
  23. stage('构建 Docker 镜像') {
  24. container('docker') {
  25. echo "构建 Docker 镜像阶段"
  26. }
  27. }
  28. stage('运行 Kubectl') {
  29. container('kubectl') {
  30. echo "查看 K8S 集群 Pod 列表"
  31. sh "kubectl get pods"
  32. }
  33. }
  34. }
  35. }