安裝Jenkins+git獲取程式碼+maven編譯+遠端釋出
安裝git
yum install -y git
安裝maven與ant
wget http://repos.fedorapeople.org/repos/dchen/apache-maven/epel-apache-maven.repo -O /etc/yum.repos.d/epel-apache-maven.repo
yum -y install apache-maven
yum -y install ant
在centos7上安裝Jenkins
安裝
新增yum repos,然後安裝
sudo wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat/jenkins.repo
sudo rpm --import https://jenkins-ci.org/redhat/jenkins-ci.org.key
sudo yum install jenkins
啟動和停止
sudo service jenkins start/stop/restart
sudo chkconfig jenkins on
修改jenkins啟動使用者
vi /etc/sysconfig/jenkins
JENKINS_USER=”jenkins”改成JENKINS_USER=”root”
這樣就是以root使用者啟動了
修改jenkins埠
vi /etc/sysconfig/jenkins
JENKINS_PORT=”8080”
最後儲存,重啟jenkins服務
service jenkins restart
安裝maven外掛
系統設定–管理外掛
publish over ssh
系統管理–系統設定
新增 SSH Servers
點選儲存
新建任務–
配置git地址
構建觸發條件—-*/3 * * * * 每更新程式碼3秒後更新
build選項中使用一下命令不執行單元測試用例(clean install -Dmaven.test.skip=true)
設定構建前刪除專案的target目錄(rm -rf /var/lib/jenkins/workspace/business/target/)
設定工具成功後操作—(
mv /var/lib/jenkins/workspace/business/target/business-*.jar /var/lib/jenkins/workspace/business/target/business.jar;
yes|cp /var/lib/jenkins/workspace/business/target/business.jar /opt/tomcat/webapps/business.jar;
cd /opt/pj/;
echo “wsExecute shell Finish”BUILD_ID=dontKillMe nohup ./restart.sh &
)無輸出執行jar
設定構建成功後ssh遠端程式碼操作—(
mv /opt/sshcache/business.jar /opt/pj/business.jar;
cd /opt/pj/;./restart.sh > nohup.out &
)拷貝程式碼-執行重啟jar指令碼不要輸出
關於jenkins publish over ssh遠端釋出使用參考
https://blog.csdn.net/houyefeng/article/details/51027885
https://blog.csdn.net/houyefeng/article/details/51027885