Jenkins deployment, continuous integration and deployment (CICD)

Keywords: Tomcat Java jenkins ansible

Catalog:

  1. Jenkins deployment process
  2. Jenkins continuous integration - publish JAVA website code example

Jenkins deployment process

  1. Download Jenkins war package
wget http://mirrors.jenkins-ci.org/war-stable/2.150.1/jenkins.war
  1. Configure java JDK, decompress and install
tar xvf jdk1.8.0_131.tar.gz
mkdir -p /usr/java/
mv jdk1.8.0_131/ /usr/java/
  1. Configure java environment variables, and add them at the end of the / etc/profile configuration file
export JAVA_HOME=/usr/java/jdk1.8.0_131
export CLASSPATH=$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib
export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH:$HOMR/bin

Load environment variables and view java version

[root@localhost ~]# source /etc/profile

[root@localhost ~]# java -version
java version "1.8.0_131"
Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)
  1. Tomcat configuration
# Download tomcat package
wget http://mirror.bit.edu.cn/apache/tomcat/tomcat-8/v8.5.47/bin/apache-tomcat-8.5.47.tar.gz
# decompression
tar xvf apache-tomcat-8.5.47.tar.gz
# Create tomcat directory
mkdir -p /usr/local/tomcat/

cp apache-tomcat-8.5.47/* /usr/local/tomcat/

cd /usr/local/tomcat/webapps/ROOT

cp /root/jenkins.war .

jar -xf jenkins.war
# Start tomcat service
[root@localhost ROOT]# /usr/local/tomcat/bin/startup.sh
  1. Access port 8080 of the host, note: if you visit the supermarket, please check the firewall and selinux configuration.
  2. After entering the password in the file, click all the way

Back to directory



Jenkins continuous integration - publish JAVA website code example

  • Jenkins is an open-source and free software project management platform, which processes all business modules at the bottom. Jenkins combines all modules and associates modules, steps and processes.
  • JAVA website code developers usually use Ant and Maven to manage the source code: website source code compilation, code packaging, code unit testing, code BUG processing, etc., while JAVA website code (business system) is programmed through software? Eclipse|IDEA, etc.
  • Requirements: JAVA developers have developed a set of JAVA business system, named EDU (education system). Developers upload the source code of business system to SVN file management server.

Actual operation process

  1. Based on Jenkins WEB platform - create JOB project (Maven style);
  2. Configuration JOB project name: edu (named after the business system name);
  3. Fill in the URL access address of SVN|GIT warehouse (for remote download of source code);
  4. Jenkins server deploys Maven software tools & sets the path of JDK and Maven tools; (otherwise, compilation cannot be carried out);
  5. Click Project Engineering - build now - generate JAVA's WAR package; (Automation)
  6. Copy or deploy the website code WAR to the remote server (implemented manually);
  7. Bulk deploy the edu.war package to the following four docker containers:
    172.17.0.2
    172.17.0.3
    172.17.0.4
    172.17.0.5
ansible www-edu -m  copy -a "src=/root/www-edu/apache-tomcat-8.0.50.tar.gz dest=/root/"
ansible www-edu -m  copy -a "src=/root/www-edu/jdk1.8.0_131.tar.gz dest=/root/"
ansible www-edu -m shell -a "yum install -y tar gzip*"
ansible www-edu -m shell -a "cd /root;tar -xf apache-tomcat-8.0.50.tar.gz"
ansible www-edu -m shell -a "cd /root;tar -xf jdk1.8.0_131.tar.gz"
ansible www-edu -m shell -a "cd /root;mkdir -p /usr/java/;mv jdk1.8.0_131 /usr/java/;mv apache-tomcat-8.0.50 /usr/local/tomcat/"
ansible www-edu -m shell -a "sed -i '/JAVA_HOME/d;/CLASSPATH/d' /etc/profile"
ansible www-edu -m shell -a  "echo -e 'export JAVA_HOME=/usr/java/jdk1.8.0_131\nexport CLASSPATH=\$CLASSPATH:\$JAVA_HOME/lib:
\$JAVA_HOME/jre/lib' >>/etc/profile"
ansible www-edu -m shell -a  "rm -rf /usr/local/tomcat/webapps/*;mkdir /usr/local/tomcat/webapps/ROOT"
ansible www-edu -m copy -a "src=/root/.jenkins/workspace/www.jfedu.net/target/edu.war dest=/usr/local/tomcat/webapps/ROOT/"
ansible www-edu -m shell -a  "cd /usr/local/tomcat/webapps/ROOT;source /etc/profile ;\$JAVA_HOME/bin/jar -xf edu.war"
ansible www-edu -m shell -a  "source /etc/profile;set -m;/usr/local/tomcat/bin/shutdown.sh"
ansible www-edu -m shell -a  "source /etc/profile;sleep 2;set -m;/usr/local/tomcat/bin/startup.sh"

  1. You can put the script in the post build step and deploy it automatically. Note: when deploying automatically, remember to back up the previous code.

Back to directory

Posted by kaveman50 on Wed, 23 Oct 2019 20:36:47 -0700