Centos uses git node shell for continuous integration

Keywords: Maven git Java github

catalog

preface

After listening to the teacher's lesson yesterday, I want to make continuous integration by myself. I have made many detours from five to eleven. Here, I will record the steps and experience of implementation

preparation

  • Install jdk
#Install jdk using yum
yum install java-1.8.0-openjdk.x86_64 java-1.8.0-openjdk-devel.x86_64 
#Check whether the installation is successful
java -version


If the version number appears, the installation is successful

  • Setting environment variables for jdk
#You can see the installation path of jdk here
ls /usr/lib/jvm/

vi /etc/profile

Open the configuration file and add the following code at the end

export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.252.b09-2.el8_1.x86_64
export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/bin

Refresh environment variables

source /etc/profile
  • Install maven

Using wget to download network resources

wget http://mirrors.cnnic.cn/apache/maven/maven-3/3.3.9/binaries/apache-maven-3.3.9-bin.tar.gz

decompression

tar vxf apache-maven-3.3.9-bin.tar.gz

Change the name of the downloaded maven

mv apache-maven-3.3.9 /root/maven-3.3

Modify profile

vi /etc/profile

Add at the end of the file

# maven
export MAVEN_HOME=/root/maven-3.3
export PATH=$MAVEN_HOME/bin:$PATH

Refresh environment variables

source /etc/profile

Check whether maven is installed successfully

mvn -v  

  • Install git
 yum install git

Check if the installation is successful

git --version

  • Install node
 yum module install nodejs
node --version

Creating a springboot project

My eclipse, right-click - > New - > other
Select spring starter project

For demonstration, I only chose one web module


Create a controller

package cn.edu.bcu.ls.controller;


import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class IndexController {
	@RequestMapping("/")
	public String index() {
		return "hello word ls zjx 16";
	}
}

Create a warehouse on github



Here's a name. I've already created it, so I won't create it anymore

The new project here is an empty copy of the link on the right, which can be connected with eclipse (I will not talk about it here)

Select Setting on the top and Webhooks on the left

Select Add webhook

Write listening server of node

Here is the teacher's ciserver.js Code:)

//Reference http module
const http=require('http')
//Quote child_process module
let child = require('child_process');
let server=http.createServer();
server.on('request',(req,resp)=>{
            resp.end("hello")
            console.log("11")
            child.exec('./git.sh', function(err, sto) {
                            console.log("22")
                            console.log(sto);
                            console.log("33")

                            
                        })
        

})
//Enable listening on port 3001
server.listen(3001)

Remember to download child on the server here_ Process module

npm install child_process --save

Upload to the server and start it in the background with node

nohup  node ciserver.js &

to write git.sh script

#! /bin/bash
echo "start clone"
# Here I find that if there's a project directory in the directory, I won't download the new one, so every time clone wants to delete it
if [ ! -d "/root/workspace/GitHook" ];then
git clone https://github.com/vicmeng/GitHook.git
else
        echo "Existing change directory deleted"
        rm -r  /root/workspace/GitHook
        git clone https://github.com/vicmeng/GitHook.git
fi
#I tried to delete the jar package yesterday. It seems that the process will still be there, so I'm going to kill port 8081 here
lsof -i :8081|grep -v "PID"|awk '{print "kill -9",$2}'|sh

echo "Enter working directory"
#Go to you pom.xml I don't know how it can be that there is a layer of directory outside
cd  /root/workspace/GitHook/GitHook
echo "mvn package"
mvn clean package
cd target
echo "Background execution"
nohup java -jar  GitHook-0.0.1-SNAPSHOT.jar &
echo "completion of enforcement"
~                 

Final test

Start node service

Submit the modified code in the local eclipse


Click commit and push directly

push over

It's started here

Page modification completed!

Posted by ryanpaul on Tue, 23 Jun 2020 21:23:21 -0700