Jenkins automatically deploys learning

Premise:

Blank system

Preparatory work

Install the JDK

cd /usr/local/jdk

Run the following command to download the JDK to the specified directory

wget https://download.oracle.com/otn/java/jdk/8u281-b09/89d678f2be164786b292527658ca1605/jdk-8u281-linux-x64.tar.gz?AuthParam =1617168763_f679dc8e6793bc203f3f221f414de5f5Copy the code

When the download is complete, unzip it

tar -zxvf jdk-8u281-linux-x64.tar.gz

Perform ll

Modifying folder Names

The mv jdk1.8.0 _281 / jdk8

To configure the environment variables, enter the following command:

vim /etc/profile

Add it at the bottom of the file

export JAVA_HOME=/opt/jdk8
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH
Copy the code

Install the Node

Run the following command to download the node

yum install nodejs
Copy the code

Install git

yum install git -y
Copy the code

performgit versionCheck whether Git is successfully installed

git version
Copy the code

Install maven

Go to the specified directory

cd /opt/server

Download maven

Wget HTTP: / / https://mirrors.tuna.tsinghua.edu.cn/apache/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gzCopy the code

Unpack the

The tar ZXVF - apache maven - 3.6.3 - bin. Tar. GzCopy the code

Configuring environment Variables

Export M2_HOME = / opt/server/apache maven - 3.6.3 export PATH = $PATH: $M2_HOME/binCopy the code

Reload data

source /etc/profile
Copy the code

View the Maven version

mvn -version
Copy the code

Install Jenkins

Download Jenkins

www.jenkins.io/download/

Download the Jenkins. War package at the following address.

After downloading, upload the WAR package to /usr/local/Jenkins

Install Jenkins

Perform the war package

java -jar jenkins.war -httpPort=9999
Copy the code

The Jenkins initialization password is shown in the figure

Enter the corresponding connection address: http://XXXX:9999 to open the Jenkins page

Enter the password you copied earlier and select the plugins Jenkins recommends

Create an account and go to the background management page.

Configuration Jenkins

Change to use Tsinghua source

Manage Jenkins -> Manage Plugins -> Advanced -> Upgrade site

Enter the source below

https://mirrors.tuna.tsinghua.edu.cn/jenkins/updates/current/update-center.json
Copy the code

Keep Jenkins running for a long time

Run the nohup command

nohup java -jar jenkins.war --httpPort=9999
Copy the code

This command is executed with an error:

Ignoring input and appending output to 'nohup. Out'Copy the code

The modification command is as follows:

nohup java -jar jenkins.war --httpPort=9999 > /dev/null 2>&1 &
Copy the code

You can start it in the background

The wheel test

Create a VUE project capable of continuous integration and deployment using Jenkins.

Make sure you currently have a project on Github and pull it through Jenkins.

preparation

  1. Github creates a project called test-Jenkins

  2. Use SSH to generate the private and public keys on Jenkins’ deployment machine (this is optional if the current project is public).

3. Copyid_ras.pubFile the contents to github’s public key field and configure a new sshkey.

4. Jenkins configures his own private key

System Administration -> Security -> Manage Credentials -> Global -> Add Credentials

Click Save.

Jenkins creates the project

The example project I’m using here is vue-element-template

  1. Jenkins configures Nodejs. The Nodejs version needs to be configured according to the version you need for your current project.

    Configure Nodejs using the following path

    System Administration -> Global Tools Configuration ->NodeJS configuration, select the version you want. Here I choose 8.16

    If this option is not currently available, or if NPM reports a subsequent error, you may need to install the NodeJS plug-in

  1. Install the NodeJS plug-in.

    System Administration --> Plug-in Administration --> Search NodeJs

  1. Create Jenkins Project

Click OK to create a Test project.

  1. Go back to DashBoard, select the project you just created, and start the configuration, starting with configuring your Git source

    Configure the repository URL. If it is a public project, the Credentials need not be configured.

    The branch is going to follow the branch requirements of your project, so in my case, master,

  1. Configuring triggers

The function of Jenkins timing pulling code and automatic release can be realized by configuring trigger.

  1. Then configure the build environment. Select Provide Node…. Choose your own version of Node.

  1. The build

    #! /bin/bash rm -rf. /dist/* # - registry=https://registry.npm.taobao.org # && configuration taobao mirror CNPM install & # & installation node package depends on NPM run build: prod # packaged command rm - rf Usr /local/web/ usr/local/web/ usr/local/web/ usr/local/web/ usr/local/webCopy the code
  2. When the configuration is complete, click Build Now.

    If the following information appears, the build is complete.

9. If the nginx server is running, refresh the page to see the successfully deployed page.

  1. Nginx configuration
location / {
	root '/usr/local/web/';
    try_files $uri /index.html;
    index index.html index.htm index.php;
}
Copy the code