亲宝软件园·资讯

展开

Docker 安装Jenkins

SpriCoder 人气:0

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安全内容配置策略

加载全部内容

相关教程
猜你喜欢
用户评论