Jenkins automated deployment projects (SpringBoot to Docker)

Install the JDK

  • yum install -y java

Installation jenkins

After the installation directory in / var / lib / jenkins /

Yum repository library to add Jenkins, Jenkins will install download here.

  • wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat/jenkins.repo

  • rpm --import https://jenkins-ci.org/redhat/jenkins-ci.org.key

  • yum install -y jenkins

    • If the last step can not be installed on to the official website to download jenkis of rmp package, the official website address (http://pkg.jenkins-ci.org/redhat-stable/)
      • wget http://pkg.jenkins-ci.org/redhat-stable/jenkins-2.7.3-1.1.noarch.rpm
      • rpm -ivh jenkins-2.7.3-1.1.noarch.rpm

Configure port jenkis of (start time from / etc / sysconfig / jenkins obtain configuration parameters)

  • vi /etc/sysconfig/jenkins

    Found modify the port number: JENKINS_PORT = "8080" (this port does not conflict can not be modified)

Modify the address jenkins download plug-ins

  • sed -i 's/http:\/\/updates.jenkins-ci.org\/download/https:\/\/mirrors.tuna.tsinghua.edu.cn\/jenkins/g' /var/lib/jenkins/updates/default.json && sed -i 's/http:\/\/www.google.com/https:\/\/www.baidu.com/g' /var/lib/jenkins/updates/default.json

Start jenkins

  • service jenkins start/stop/restart
    Will serve as a daemon to start with the system, the system creates a "jenkins" allows the user to the service, if you change the owner of the service, while the need to modify the / var / log / jenkins, / var / lib / jenkins, and / var / cache / jenkins owner

Open jenkins

  • Access in the browser: the installation of Jenkins ip: JENKINS_PORT
  • In the initial password: / var / lib / jenkins / secrets / initialAdminPassword
  • Recommended plug-in installation
  • Create a new user

Installation maven plugin

  • 前往 Manage Jenkins -> Manage Plugins -> Available
  • Right side Filter Input: Maven Integration
  • Check the list below optional Maven Integration (such as Maven Integration does not exist in the list, then click Check now update the list of plugins)
  • 点击 Download now and install after restart

Configuring Maven repository address

Jenkins the Manage -> the Configure System
-Dmaven.repo.local=/var/lib/jenkins/workspace/jars(then created jars directory)
Here Insert Picture Description

Configuring JDK, Git, Maven address

Manage Jenkins -> Global Tool Configuration
Here Insert Picture Description

Here Insert Picture Description

Here Insert Picture Description

  • Note: Git is to be configured to: GIT_HOME / bin / git
  • Installation and maven git Reference: https: //blog.csdn.net/weixin_43934607/article/details/100538881

Add Item

New Project
Here Insert Picture Description
Set git path
Here Insert Picture Description
command set build
clean install -Dmaven.test.skip=true
Here Insert Picture Description
try to build the project
Here Insert Picture Description

  • Special Note: If you have to use it to build swagger generated api documentation fails to remove the content in the pom file

After building a successful deployment settings

Here Insert Picture Description

  • Note: Jenkins docker not have permission to operate, it must firstchmod 777 /var/run/docker.sock
#!/bin/bash
echo "开始运行"
echo "停止app"
docker stop app
echo "删除容器app"
docker rm app
echo "删除镜像yzx/accout-mange:latest"
docker rmi -f yzx/accout-mange:latest

#要把jar包制作成镜像就必须使用docker build命令 同时必须有对应的Dockerfile(指定jar包位置是在Dockerfile指定)
# . 表示当前目录 -f 参数指定Dockerfile文件  -t 表示 制作的镜像tag 
cd /var/lib/jenkins/workspace/accout-mange
docker build -f Dockerfile  -t  yzx/accout-mange:latest  .

echo "新容器id:"
docker create --name app \
-p 9999:8080 \
-v /tmp/accout:/tmp/accout \
yzx/accout-mange:latest

echo "启动容器名:"
docker start app

echo "执行完毕,浏览器打开IP:9999浏览"
#构建镜像的Dockerfile
# From java image, version : 8
FROM java:8

# 挂载app目录
#VOLUME /app

##将maven构建好的jar添加到镜像中
ADD target/accout-mange-1.0-SNAPSHOT.jar accout-mange-1.0.jar

EXPOSE 8080

ENTRYPOINT ["java", "-jar", "accout-mange-1.0.jar"]

Set the build before the trigger (Gitee)

Plug-in installation

  • 前往 Manage Jenkins -> Manage Plugins -> Available
  • Right side Filter Input: Gitee
  • 点击 Download now and install after restart

Plug-in configuration

  • Add code cloud link configuration
    Go Jenkins -> Manage Jenkins -> Configure System -> Gitee Configuration -> Gitee connections
  • Enter Gitee or the name you want in the Connection name in
  • Enter the code complete cloud Gitee host URL in the URL address: https://gitee.com (yards privatization cloud deployments customers enter the domain name)
  • Credentials in the code has not been configured as a private cloud APIV5 token, click Add -> Jenkins
    • Domain select Global credentials
    • Kind choice Gitee API Token
    • Scope choice you need
    • Gitee API Token Enter your code private cloud token, get the address:https://gitee.com/profile/personal_access_tokens
    • ID, Descripiton to enter the ID and description you want.
  • Credentials choose configured Gitee APIV5 Token
  • Click Test Connection to test the link was successful.

Trigger Configuration
Here Insert Picture Description
Here Insert Picture Description

  • Click to generate a password WebHook

Gitee Configuration
Here Insert Picture Description

Published 109 original articles · won praise 47 · views 30000 +

Guess you like

Origin blog.csdn.net/weixin_43934607/article/details/104217800