Jenkins+tomcat Automated Deployment + nginx+apidoc document generation

2021SC@SDUSC

Integrated Automated Deployment

Jenkins installation configuration

Installation related environment

  1. Run the following command to configure the Jenkins environment

    # Download add key
    wget -q -O - https://pkg.jenkins.io/debian-stable/jenkins.io.key | sudo apt-key add -
    # Add apt warehouse source for Jenkins
    sudo sh -c 'echo deb https://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'
    # Update warehouse source
    sudo apt-get update
    # Install jenkins
    sudo apt-get install jenkins
    

    The above image source may not be accessible in China, so you can use it instead Tsinghua source

    wget https://mirrors.tuna.tsinghua.edu.cn/jenkins/debian-stable/jenkins_2.303.2_all.deb
    sudo dpkg -i jenkins_2.303.2_all.deb
    

    If the installation fails, dpkg: dependency problems prevent configuration of jenkins:

    Execute the following commands in sequence

    sudo apt-get install --reinstall python
    sudo apt-get -f install
    sudo dpkg -i jenkins_2.303.2_all.deb
    
  2. Install jdk8/jdk11

    sudo apt install openjdk-11-jdk
    
  3. Installing maven

    sudo apt install maven
    
  4. Install git

    sudo apt install git
    
  5. Install tomcat,nginx

Start Jenkins

Edit the / etc/default/jenkins file and change the port because the 8080 is occupied

# port for HTTP connector (default 8080; disable with -1)
HTTP_PORT=9090

If there is a firewall, check whether port 9090 is open

sudo systemctl daemon-reload
sudo systemctl restart jenkins
sudo systemctl status jenkins

Configure Jenkins

View the initial Jenkins password inside / var/lib/jenkins/secrets/initialAdminPassword

Visit your_ip:9090 or localhost:9090

Enter the management interface

Selecting the recommended plug-in will enable automatic download

Wait until the plug-in download is completed, then optionally create an account or continue with the administrator account, and then select the default Jenkins url

visit http://localhost:9090/pluginManager/installed Management plug-ins

Add GitHub plugin, Maven integration plugin and deploy to container plugin

New project

Configure github hook credentials

  1. First, generate the local ssh key

    ssh-keygen -t rsa -C "your_email@youremail.com"
    

  2. Enter the github repository and create deploy keys

    Fill in cat ~ /. SSH / ID in the Key_ The result of rsa.pub is similar to the following string

  3. visit personal access token Generate a new token, grant repo and admin:repo permissions, and save the generated token

  4. adopt http://localhost:9090/configure Enter the Jenkins configuration management interface and find Github Server

    Add credentials, select secret text, and fill in the Secret with the token generated in the previous step

  5. Check the credentials generated in the previous step and test the connection

Add ssh credentials

visit Add address for credentials

Create a new ssh private key configuration

The following Private key fills in the execution cat ~/.ssh/id_rsa results

Add tomcat configuration

Select user name with password where you want to add clean and jerk, and add the user name and password of tomcat

Project configuration

  1. Check build maven project

  2. Configuration source code management is used to pull build code

  3. Configure triggers for automatic build of code updates

  4. Configure build environment

  5. Build the document before building, or build the document after the Post Steps setting is completed

  6. Build generally skips tests

    clean install -D maven.test.skip=true
    

    Initially, you need to configure the location of maven, and the shell can obtain Maven by executing mvn -v_ home

    visit This URL to configure

  7. The war package name needs to be consistent with the maven configuration for automatic deployment after construction

    If the post build operation does not have Deploy war/ear to a container, [configure Jenkins necessary plug-ins]

Configure apidoc

Install apidoc

# Install nodejs and npm and update
sudo apt install nodejs
sudo apt install npm
# Updating nodejs is very important, otherwise apidoc will not run
sudo npm install n -g
sudo n stable
# Use the image npm to update the list
sudo npm config set registry https://registry.npm.taobao.org
sudo npm config list
# Global installation of apidoc
sudo npm install apidoc -g

Configure nginx

  1. Find the nginx configuration file directory, which is generally located in / etc / nginx / site enabled/

  2. View the default file and the location of the root directory of the site

  3. Jump to the root directory and create a new folder doc

    This is consistent with the generation directory of apidoc configured above

    sudo mkdir doc
    # Make sure you have write permission
    sudo chmod 777 doc/ -R
    
  4. Try a push to test the generated results

Tags: jenkins Tomcat

Posted on Sat, 30 Oct 2021 04:53:03 -0400 by jonorr1