1:jenkins安装github插件
2:新建一个自由风格的项目
——- 选用github 填写项目url(…git)
——-源码管理选用git 添加连接github信息 可在系统配置中或首页添加
——-填写构建脚本
3:在github对应的项目Setting中添加webhook
——payloadURL: http://www.example-jenkins.com:8080/github-webhook
——触发条件:默认push事件 可勾选自定义
4: 解决shell执行后nohup进程却被jenkins杀死问题
java -Dhudson.util.ProcessTree.disable=true -jar jenkins.war
其他方式参考:https://wiki.jenkins.io/display/JENKINS/ProcessTreeKiller
linux构建脚本实例:
sh /root/test.sh
ps -ef | grep jenkins_test
/root/test.sh
#!bin/sh
sh /root/.jenkins/jar-restart.sh test jenkins_test-1.0-SNAPSHOT 6
/root/.jenkins/jar-restart.sh
#!/bin/sh
#重启jar
jarPath="/root/.jenkins/workspace/$1/target/$2.jar"
logPath="/root/.jenkins/jar-run-logs"
echo $jarPath
echo $logPath
if [ -e ${jarPath} ]
then echo "存在$2.jar文件,正准备重新运行..."
#pkill -9 $jarPath 无效
kill `ps -ef |grep $jarPath | grep -v grep|awk '{print $2}'`
if [ ! -d ${logPath} ]
then mkdir -p ${logPath}
fi
nohup java -jar ${jarPath} > ${logPath}/$1.log 2>&1 &
sleep $3
more ${logPath}/$1.log
else
echo "$2.jar文件不存在!"
fi
jenkins+github文章参考:
http://blog.csdn.net/u013066244/article/details/52611070
http://blog.csdn.net/u011781521/article/details/77914344
http://blog.csdn.net/u011904605/article/details/54590383
解决shell进程被jenkins杀死参考:
http://blog.csdn.net/houyefeng/article/details/52269366
https://wiki.jenkins.io/display/JENKINS/ProcessTreeKiller