Principle of automatic deployment: The Git commit code repository will send a record to your configured server, the server will parse the record to analyze the corresponding project and determine what operations should be done for the branch commit, and then execute the preset shell script. We use Jenkins to handle hook response.

Jenkins relies on the Java environment and has Jdk and Tomcat installed on the default server

0. Start the installation

Download the war file http://mirrors.jenkins.io first

After opening the web page, follow the prompt to find the password in the corresponding file of the server, enter and enter the new installation, select the default installation, ignore it at this time, there should be a series of failures, first enter the corresponding directory of Tomcat just installed:

Go to the \ web-INF \detached-plugins folder and check if there is a cloudbees- Folder. hpi file. If it is missing, download it manually and put it in.

Into the working directory (not the installation directory, usually in the root folder. Jenkins folder), find the Hudson. Model. UpdateCenter. XML this file, Change the URL to https://updates.jenkins-zh.cn/update-center.json

In the updates folder default.json file in your working directory, replace all http://updates.jenkins-ci.org/download/ with https://updates.jenkins-zh.cn/

This is to make sure the initialization doesn’t get stuck due to network issues, restart Jenkins and wait for the installation to complete.

1. Create a user

Git Manager -> Global Tool Config… Insert Path to Git executable into /usr/local/git/bin/git

Select GitHub > Advanced. Select Hook URL. Payload URL = http://github/Webhook /

Go to GitHub and click On Setting. Go to the setting page and click on Developer Settings in the lower left corner to jump to Personal Access Tokens and create tokens. Check repO and admin: rePO_hook.

Enter Jenkins configure to configure githubserver, (Credentials)Add Select “secret text” — enter the token, and check the management hook

Yum configure domestic source (omitted)

/etc/resolv.conf nameserver 114.114.114.114 nameserver 8.8.8.8Copy the code

2. Git

Download GIt mirrors.edge.kernel.org/pub/softwar…

git --version yum remove -y git yum -y install libcurl-devel expat-devel curl-devel gettext-devel openssl-devel zlib-devel yum -y install gcc perl-ExtUtils-MakeMaker cd /usr/local/src/ wget https://mirrors.edge.kernel.org/pub/software/scm/git/git-2.1.1.tar.gz tar - ZVXF git - 2.1.1. Tar. Gz CD git - 2.1.1 the make prefix=/usr/local/git all make prefix=/usr/local/git installCopy the code

Adding Git to environment variables (possible)

echo "export PATH=$PATH:/usr/local/git/bin" >> /etc/bashrc
source /etc/bashrc
Copy the code

Note that Settings Webhooks configure payload for push on Github.

3. Common configuration examples

Note: Delete Workplace…. in Build Environment is not selected Increases build time.

4. Commonly used build shell records

Chmod -r 775 / chmod -r 775 / chmod -r 775 / chmod -r 775 /Copy the code