下载https://jenkins.io/download/ Centos版本
rpm 安装 jenkins
rpm -ivh jenkins-2.73.2-1.1.noarch.rpm
查看状态
service jenkins status
启动
service jenkins start
安装插件
Deploy to container Plugin
Git plugin
Maven Integration plugin
配置
Global Tool Configuration
JDK配置
别名jdk
JAVA_HOME /usr/java/jdk1.8.0_111
Git配置
Name Default
Path to Git executable git
Maven配置
name maven
MAVEN_HOME /usr/local/apache-maven-3.5.2
简单轮询发布
新建一个spring boot 项目
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 新建 -> 构建一个maven项目
源码管理 -> Git -> Repository URL (填写自己项目)
构建触发器 -> Build whenever a SNAPSHOT dependency is built
每1分钟轮询
->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"