Method of realizing automated deployment based on Docker+Jenkins

Method of realizing automated deployment based on Docker+Jenkins

Use Code Cloud to build a Git code storage warehouse

https://gitee.com/login

  • Use Code Cloud to create a private git repository
  • Upload the local springboot project to the git repository

Install Jenkins environment based on Docker

1. Install Jenkins using Docker

docker run -p 8080:8080 -p 50000:50000 -v jenkins_data:/var/jenkins_home jenkinsci/blueocean

2. Access Jenkins address 8080

Note: When starting for the first time, it will take about 3-10 minutes for Jenkins to load.

3. Unlock Jenkins

docker exec -it 7f485bd95c3b /bin/bash enter the jenkins container cat /var/jenkins_home/secrets/initialAdminPassword 

It takes about 3-10 minutes to wait

Create a new user

Jenkins global tool configuration

Enter the jenkins container and echo $JAVA_HOME to get the java environment installation address

JDK environment installation

Maven environment installation

Install the Jenkins corresponding Maven plugin

Find "System Management" - "Install Plugin", click "Optional Plugin", and find the following Maven plugin version

Plugin NameMaven Integration

Jenkins implements Springboot project automatic deployment to create a new release task

Configure the task git account and password

3. Project packaging

clean install

Click Build Now

The first build may take a long time because you need to download some related dependent jar packages

Execute the shll script after Jenkins starts successfully

#!/bin/bash
#Service name SERVER_NAME = springboot
# Source jar path, after mvn packaging is completed, the jar package name in the target directory can also be selected as a war package. The war package can be moved to the webapps directory of Tomcat for operation. Here, the jar package is used and the java -jar command is used to execute JAR_NAME=springboot-0.0.1-SNAPSHOT
# Source jar path #/usr/local/jenkins_home/workspace--->jenkins working directory #demo project directory #target package generated jar package directory JAR_PATH=/var/jenkins_home/workspace/springboot/target
# After packaging is completed, move the jar package to the directory where the jar package is run--->work_daemon. The work_daemon directory needs to be created in advance JAR_WORK_PATH=/var/jenkins_home/workspace/springboot/target
 
echo "Query process id-->$SERVER_NAME"
PID=`ps -ef | grep "$SERVER_NAME" | awk '{print $2}'`
echo "Get process ID: $PID"
echo "End process"
for id in $PID
do
kill -9 $id 
echo "killed $id" 
done
echo "End process completed"
 
#Copy the jar package to the execution directory echo "Copy the jar package to the execution directory: cp $JAR_PATH/$JAR_NAME.jar $JAR_WORK_PATH"
cp $JAR_PATH/$JAR_NAME.jar $JAR_WORK_PATH
echo "Complete jar package copy"
cd $JAR_WORK_PATH
#Change file permissions chmod 755 $JAR_NAME.jar
Nohub java -jar $JAR_NAME.jar

Adding nohub means running in the background, or using nohub &

Container maps port 8081

1. Restart the container

systemctl restart docker

2. Clear non-running containers

docker rm $(sudo docker ps -a -q)
docker run -p 8080:8080 -p 8081:8081 -p 50000:50000 -v jenkins_data:/var/jenkins_home jenkinsci/blueocean

This is the end of this article about automated deployment based on Docker+Jenkins. For more information about automated deployment based on Docker+Jenkins, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Jenkins+Docker+Gitee+SpringBoot automated deployment
  • Automated front-end deployment based on Docker, Nginx and Jenkins
  • Docker+gitlab+jenkins builds automated deployment from scratch
  • How to build docker+jenkins+node.js automated deployment environment from scratch
  • Docker builds Jenkins and automates the steps of packaging and deploying projects

<<:  Detailed tutorial on deploying Jenkins based on docker

>>:  JavaScript implements an input box component

Recommend

MYSQL local installation and problem solving

Preface This article is quite detailed and even a...

Use Rem layout to achieve adaptive

I have written an article about mobile adaptation...

HTML markup language - reference

Click here to return to the 123WORDPRESS.COM HTML ...

Detailed explanation of HTML form elements (Part 2)

HTML Input Attributes The value attribute The val...

Does MySql need to commit?

Whether MySQL needs to commit when performing ope...

MySQL free installation version configuration tutorial

This article shares the MySQL free installation c...

Javascript Basics: Detailed Explanation of Operators and Flow Control

Table of contents 1. Operator 1.1 Arithmetic oper...

3 ways to create JavaScript objects

Table of contents 1. Object literals 2. The new k...

Docker starts Redis and sets the password

Redis uses the apline (Alps) image of Redis versi...

SQL query for users who have placed orders for at least seven consecutive days

Create a table create table order(id varchar(10),...

How to dynamically modify container port mapping in Docker

Preface: Docker port mapping is often done by map...

Detailed explanation of the use of vue-resource interceptors

Preface Interceptor In some modern front-end fram...

Vue echarts realizes horizontal bar chart

This article shares the specific code of vue echa...

Vue uses the method in the reference library with source code

The official source code of monaco-editor-vue is ...