preface

After local write code to deploy on the tomcat server is indeed a troublesome, need to war file, and then uploaded to the server, restart tomcat, really is a troublesome thing, as a programmer can do this duplication and no technical content, so he thought of using Jenkins to automate, I only responsible for Hand in the code, nothing else, is also a great thing.

preparation

  1. Maven (MVN clean install) maven(MVN clean install)
Vim /etc/profile./ at the end of this fileexportMAVEN_HOME = / root/maven3.4.5export PATH=$MAVEN_HOME/bin:$PATH/etc/profile // Save the configuration file and enter it on the CLI to start the configurationexportLook at the output to see if the configuration was successfulCopy the code
  1. JDK (I chose java8. Anyway, there are a lot of installation tutorials online, so I won’t go into details here)
  2. Git (yum -y install git) 4. Jenkins (it is recommended that you download the latest version from Jenkins’ official website. I installed it using RPM, of course docker can also be installed, but docker may encounter directory and path problems during some configuration, so it needs to mount directories, which is really painful)
RPM vi /etc/sysconfig/jenkins: RPM -ivh jenkins-2.175-1.1.noarch. RPM# change the user and port.
JENKINS_USER="root"
JENKINS_PORT="8888"
systemctl start jenkins
Then you can go to IP+8888 directly to install the plugin. After that, you will pop up a screen that requires a password to obtain the password, select recommended installation and wait for the plugin to be installed
Copy the code

5. Mysql8 (I choose the way of docker installation because there is almost no docker can go to Baidu how to install docker)

Docker pull mysql: 8.0# --restart-always: Docker automatically starts the container when the docker service starts, and tries to restart the container when the container stops.
# MYSQL_ROOT_PASSWORD: password of user root
# --character-set-server --collation-server default database encoding and default collation
docker run --name mysql -p 3306:3306 --restart=always -e MYSQL_ROOT_PASSWORD=root -v /var/lib/mysql/:/var/lib/mysql/ -dMysql: 8.0 - character - set - server = utf8mb4 - collation - server = utf8mb4_unicode_ci dockerexec -it mysql /bin/bash
mysql -uroot -p root
Select * from user where host = 'root'
ALTER USER 'root'@The '%' IDENTIFIED WITH mysql_native_password BY 'root';
flush privileges;
Copy the code

The body of the

If all goes well, you should be presented with the following screen (which may be a little different since I have a new task):

To automate deployment packaging, Jenkins must first have access to the code from Github, and github must be able to notify Jenkins every time the code is submitted. The former we configure private token in Github, the latter use Github webhook to carry out.

Configure tokens :github->setting-> Developer setting-> Personal Access tokens->generate new Cretae will return you a token, save the token yourself, and if you lose it, you won’t be able to find it again. Note that this token is very important. It is secret text.

3. Confirm that the Github plugin has been installed in Jenkins, if not, go to the plugin management to search for the installation, and then configure authentication. System Administration > System Settings > GitHub Server > Add

Note that “secret” is the token obtained by Github before filling in. The id can be left blank and the description can be leaked.

After the setting is complete, click TestConnection, and the Credentials verified for user XXXX, rate limit: XXX are displayed.

4. System Administration -> Global Tools Management -> set up your JDK Git Maven path.

5. Certainly the most exciting environment to create a new mission (choose a free style mission): 1). Fill in the project description and project home page (github address, not the git address you downloaded, but the project home page,github.com/)

5). Select Set Github status after build

Then submit the code to enjoy the pleasure of automatic package deployment. (PS: I always report the error of MVN Clean install when packaging. After searching for several times, I find that the path configuration of the war package package plug-in is wrong, which takes a long time.

Mistakes are unavoidable