docker

关注公众号 jb51net

关闭
首页 > 网站技巧 > 服务器 > 云和虚拟化 > docker > Docker 安装Jenkins

Docker 安装Jenkins全过程及踩坑指南

作者:SpriCoder

这篇文章主要介绍了Docker 安装Jenkins 踩坑全指南,本文通过图文示例相结合给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下

Docker 安装 Jenkins

开始前最好,将docker升级到最新版本(至少大于17)

1. 安装过程

2. Jenkins 安装 npm

2.1. 替换容器的源

# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ buster main contrib non-free
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ buster main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ buster-updates main contrib non-free
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ buster-updates main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ buster-backports main contrib non-free
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ buster-backports main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian-security buster/updates main contrib non-free
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian-security buster/updates main contrib non-free

2.2. 安装nodejs和npm

3. Jenkins流水线 + Docker + Maven + Github webhooks + Spring boot 

3.1. 需要的插件和配置

3.1.1. 插件

Blue Ocean

Maven Integration

3.1.2. 配置

"Env": [
      "PATH=/usr/local/openjdk-8/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
      "LANG=C.UTF-8",
      "JAVA_HOME=/usr/local/openjdk-8",
      "JAVA_VERSION=8u242",
      "JAVA_BASE_URL=https://github.com/AdoptOpenJDK/openjdk8-upstream-binaries/releases/download/jdk8u242-b08/OpenJDK8U-jdk_",
      "JAVA_URL_VERSION=8u242b08",
      "JENKINS_HOME=/var/jenkins_home",
      "JENKINS_SLAVE_AGENT_PORT=50000",
      "REF=/usr/share/jenkins/ref",
      "JENKINS_VERSION=2.275",
      "JENKINS_UC=https://updates.jenkins.io",
      "JENKINS_UC_EXPERIMENTAL=https://updates.jenkins.io/experimental",
      "JENKINS_INCREMENTALS_REPO_MIRROR=https://repo.jenkins-ci.org/incrementals",
      "COPY_REFERENCE_FILE_LOG=/var/jenkins_home/copy_reference_file.log"
]

Git配置

Docker配置

3.1.3. 安装maven

export MAVEN_HOME=/opt/apache-maven-3.6.3
export MAVEN_HOME
export PATH=$PATH:$MAVEN_HOME/bin

编辑maven的settings.xml来替换源(位置conf/下),在<mirrors></mirrors>标签内添加一下任意一个

<mirror>
   <id>alimaven</id>
   <name>aliyun maven</name>
   <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
   <mirrorOf>central</mirrorOf>
</mirror>

3.1.4. 配置Jenkins使用Docker

apt-get update && \
apt-get -y install apt-transport-https \
     ca-certificates \
     curl \
     gnupg2 \
     software-properties-common && \
curl -fsSL https://download.docker.com/linux/$(. /etc/os-release; echo "$ID")/gpg > /tmp/dkey; apt-key add /tmp/dkey && \
add-apt-repository \
   "deb [arch=amd64] https://download.docker.com/linux/$(. /etc/os-release; echo "$ID") \
   $(lsb_release -cs) \
   stable" && \
apt-get update && \
apt-get -y install docker-ce

3.1.5. 配置Jenkins中的Git SSH

3.1.6. Github添加Webhook

3.1.7. 配置主从节点

避免出现如下报错:pending—Waiting for next available executor

3.2. 使用流水线新建任务

无法连接仓库:Command "git ls-remote -h -- git@github.com:xxx.git HEAD" returned status code 128:
stdout:
stderr: Host key verification failed.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists

4. GitLab + Jenkins + Spring Boot

4.1. 配置GitLab插件和连接

4.2. 创建项目

5. Jenkins 使用Pipeline集成Cobertura(不支持Java 1.8)

<plugin>
   <groupId>org.codehaus.mojo</groupId>
   <artifactId>cobertura-maven-plugin</artifactId>

   <configuration>
      <formats>
         <format>xml</format>
      </formats>
      <check/>
   </configuration>
</plugin>
post {
   always {
      step([$class: 'CoberturaPublisher', autoUpdateHealth: false, autoUpdateStability: false, coberturaReportFile: '**/target/site/cobertura/coverage.xml', failUnhealthy: false, failUnstable: false, maxNumberOfBuilds: 0, onlyStable: false, sourceEncoding: 'ASCII', zoomCoverageChart: false, enableNewApi: true])
   }
}

6. Jenkins 使用pipeline集成jacoco

7.参考

实用插件

Jenkins 嵌入到 Iframe

Jenkins用户组管理

配置Jenkins的分布式构建和部署

jenkins分布式构建和部署(master-slave)

  1. Jenkins官方教程
  2. Docker 安装 Jenkins (超详细)
  3. Jenkins 插件安装失败解决办法
  4. Jenkins+Docker+github+Spring Boot自动化部署
  5. Jenkins容器中安装Docker
  6. Jenkins持续集成显示pending—Waiting for next available executor
  7. 30分钟搞定 Jenkins CI
  8. gitlab webhook jenkins 403问题解决方案
  9. jenkins安全内容配置策略

到此这篇关于Docker 安装Jenkins 踩坑全指南的文章就介绍到这了,更多相关Docker 安装Jenkins内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

您可能感兴趣的文章:
阅读全文