安装jenkins

安装jdk

$ yum install java-1.8.0-openjdk-devel.x86_64
$ java -version
openjdk version "1.8.0_181"
OpenJDK Runtime Environment (build 1.8.0_181-b13)
OpenJDK 64-Bit Server VM (build 25.181-b13, mixed mode)
# 配置java_home
$ cat >> /etc/profile << EOF
export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.181-3.b13.el7_5.x86_64
export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jarexport
export PATH=$PATH:$JAVA_HOME/bin
EOF

$ source /etc/profile

下载jenkins.war

$ wget http://mirrors.jenkins.io/war-stable/latest/jenkins.war

启动

$ nohup java -jar jenkins.war > jenkins.log 2>&1 &
启动过程中日志:
Jenkins initial setup is required. An admin user has been created and a password generated.
Please use the following password to proceed to installation:

d67428e4901640d7b25cf2353bxxxxx

This may also be found at: /root/.jenkins/secrets/initialAdminPassword

# d67428e4901640d7b25cf2353bxxxxx即为初始化密码

开发端口

$ firewall-cmd --zone=public --add-port=8080/tcp --permanent 
$ firewall-cmd --reload

登录

访问:http://host:8080/
image

初始化

  • 选择推荐插件安装
  • 创建admin用户
  • 重启jenkins
  • 安装附加插件
首页->系统管理->插件管理->可选插件
安装:Git Parameter Plug-In

系统配置

配置jdk

首页->系统管理->全局工具配置

image

配置maven

# 下载安装包
$ wget http://mirrors.shu.edu.cn/apache/maven/maven-3/3.5.4/binaries/apache-maven-3.5.4-bin.tar.gz

# 解压安装包
$ tar xvf apache-maven-3.5.4-bin.tar.gz -C /usr/locat

# 写入配置
$ cat >> /etc/profile << EOF
export M2_HOME=/usr/local/apache-maven-3.5.4
export PATH=${PATH}:${M2_HOME}/bin
EOF

$ source /etc/profile

# 验证
$ mvn -v
Apache Maven 3.5.4 (1edded0938998edf8bf061f1ceb3cfdeccf443fe; 2018-06-18T02:33:14+08:00)
Maven home: /usr/local/apache-maven-3.5.4
Java version: 1.8.0_181, vendor: Oracle Corporation, runtime: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.181-3.b13.el7_5.x86_64/jre
Default locale: zh_CN, platform encoding: UTF-8
OS name: "linux", version: "3.10.0-693.el7.x86_64", arch: "amd64", family: "unix"

配置git

# 安装
$ yum install -y git
# 验证
$ git --version
git version 1.8.3.1

git代码块配置

# 生成秘钥
$ ssh-keygen -t rsa -C "sunhj000@163.com"
$ cat ~/.ssh/id_rsa.pub 

把cat输出内容添加到gitlib的配置中,并把需要jenkins拉取代码的工程添加ssh权限

配置docker

docker安装

$ yum install docker -y
$ docker -v
Docker version 1.13.1, build 6e3bb8e/1.13.1
# 开机自启动docker
$ systemctl enable docker
# 启动docker
$ systemctl start docker

docker登录harbor

$ docker login -u ${your name} harbor.sunhaojie.com

创建项目

创建任务

首页->我的视图->新建任务
输入名称:spring_boot_docker_image_test
选择:构建一个自由风格的软件项目

General配置

  • git tag配置
    image
  • filter env配置
    image
  • 项目名称
    image

源码管理

image

构建

image

运行任务

首页->我的视图->spring_boot_docker_image_test->Build with Parameters
image
选择tag, fitler类型,并点击开始构建

查看harbor

image