Download https://jenkins.io/download/ Centos version
rpm install jenkins
rpm -ivh jenkins-2.73.2-1.1.noarch.rpm
View status
service jenkins status
start up
service jenkins start
Install plugin
Deploy to container Plugin
Git plugin
Maven Integration plugin
Configuring
Global Tool Configuration
JDK configuration
alias the JDK
JAVA_HOME /usr/java/jdk1.8.0_111
Git配置
Name Default
Path to Git executable git
Maven deployment
name maven
MAVEN_HOME /usr/local/apache-maven-3.5.2
Simple poll release
Create a new spring boot project
package com.example.demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@SpringBootApplication
@RestController
public class DemoApplication {
@GetMapping
public String test() {
return "hello";
}
@GetMapping("/test2")
public String test2() {
return "hello 2";
}
@GetMapping("/test3")
public String test3() {
return "hello 3";
}
@GetMapping("/test4")
public String test4() {
return "hello 4";
}
@GetMapping("/test5")
public String test5() {
return "hello 5";
}
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
jenkins New -> maven project to build a
source code management -> Git -> Repository URL (fill in your own projects)
Build trigger-> Build whenever a SNAPSHOT dependency is built
poll every 1 minute-
> Poll SCM ( / 1 * * *)
Post Steps -> Run only if build succeeds or is unstable
#!/bin/bash
#copy file and start jar
echo "脚本开始"
jarPath=$(date "+%Y%m%d%H%M%S")
echo "结束服务"
kill -9 `ps -aux|grep demo-0.0.1-SNAPSHOT| grep -v grep | awk '{print $2}'`
echo "延迟3秒"
sleep 3s
echo "创建目录"
mkdir /data/jenkins/${jarPath}
echo "复制文件"
cp /var/lib/jenkins/workspace/Demo02/target/demo-0.0.1-SNAPSHOT.jar /data/jenkins/${jarPath}/demo-0.0.1-SNAPSHOT.jar
BUILD_ID=DONTKILLME
echo "启动服务"
nohup java -jar /data/jenkins/${jarPath}/demo-0.0.1-SNAPSHOT.jar --server.port=8081 &
echo "server started"