Jenkins+Maven打成jar包,並執行


說明:
Source files:Source files的目錄是基於當前job的目錄(可以從jenkins的安裝目錄下找到):例如當前job名稱為people-info-server,則對於root用戶,Source files中的目錄是相對於/var/jenkins_home/workspace/people-info-server目錄下的,因此,如果我們要發送people-info-server下的xx項目的jar包,這里需要填寫:xx/target/xx-0.0.1.SNAPSHOT.jar


Remove prefix:表示需要移除的目錄,比如這里填寫xx/target,則表示發布時,只把xx-0.0.1.SNAPSHOT.jar發布到遠程linux,而不包含xx/target目錄結構


Remote directory:表示需要把編譯好的war包發布到遠程linux的哪個目錄下


Exec command:需要執行的shell命令,shell命令在遠程linux服務器上.

注意: 
job名稱不能和項目名稱相同,否則上傳不了 

附上shell腳本(Post Steps – SSH Publishers–Transfers–Exec command): 

  1.  
    echo "hello address-distribution-1.0.0.jar"
  2.  
     
  3.  
    DAY=`date +%Y-%m-%d`
  4.  
     
  5.  
    pid=`ps -ef|grep address-distribution-1.0.0|grep -v grep|awk '{print $2}'`
  6.  
     
  7.  
    if [ -n "$pid" ]
  8.  
    then
  9.  
    echo 'The pid: server' $pid ' will be killed....'
  10.  
    kill -9 $pid
  11.  
    echo 'The pid: server' $pid ' will be start'
  12.  
    cp /home/warehousecloud/.jenkins/workspace/zjs-dzfd-web/target/address-distribution-1.0.0.jar /data/sonar-jenkins/ test-jar
  13.  
    echo 'copy /home/warehousecloud/.jenkins/workspace/zjs-dzfd-web/target/address-distribution-1.0.0.jar to /data/sonar-jenkins/test-jar '
  14.  
    nohup java -jar /data/sonar-jenkins/ test-jar/address-distribution-1.0.0.jar > /dev/null &
  15.  
    else
  16.  
    echo 'The pid: server' $pid ' not exist , will be start'
  17.  
    nohup java -jar /data/sonar-jenkins/ test-jar/address-distribution-1.0.0.jar > /dev/null &
  18.  
    fi
  19.  
    echo 'The pid: server' $pid ' started'

成功界面:


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM