Ubuntu16 安裝Jenkins 實現(xiàn)自動部署

首先安裝JDK, MAVEN, Tomcat。www.lxweimin.com/p/b6cf12bce5b5

1. 官網(wǎng)下載 Jenkins.war,放在tomcat-》webapps文件夾下。

2. 啟動tomcat, 訪問 ip:port/jenkins

3. 安裝 Generic Webhook Trigger插件

4. Jenkins中新建一個 maven項目


通過配置 Optional Filter后,便可以實現(xiàn)URL 攜帶 名為 id,值為 feastbooking的 參數(shù)。




最后, 附上 spring-boot-jenkins.sh 的代碼:

#!/bin/bash

# COMMAND LINE VARIABLES

projectName=$1 #iplay

serverPort=$2

preferProp=$3

#active configuration, Ex: dev

if [ x$preferProp != x ]

then

properties=--spring.profiles.active=$preferProp

else

properties=""

fi

#### CONFIGURABLE VARIABLES ######

#destination absolute path. It must be pre created or you can

# improve this script to create if not exists

destAbsPath=/usr/local/$projectName

sourFile=$WORKSPACE/target/$projectName*.jar

destFile=$destAbsPath/$projectName.jar

logFile=initServer.log

dstLogFile=$destAbsPath/$logFile

whatToFind="Started "

msgAppStarted="Application Started... exiting buffer!"

### FUNCTIONS

##############

stopServer(){

echo " "

echo "Stoping process on port: $serverPort"

fuser -n tcp -k $serverPort > redirection &

echo " "

}

deleteFiles(){

echo "Deleting $destAbsPath"

rm -rf $destAbsPath

#echo "Deleting $dstLogFile"

#rm -rf $dstLogFile

echo " "

}

copyFiles(){

echo " "

if [ ! -d "$destAbsPath" ]

then

echo "create folder $destAbsPath"

mkdir "$destAbsPath"

fi

mv $sourFile $destFile

echo "Moving files from $sourFile to $destFile"

}

run(){

output="COMMAND: nohup nice java -jar $destFile --server.port=$serverPort "

if [ $properties = "" ]

then

nohup nice java -jar $destFile --server.port=$serverPort v&

echo "$output""$"

else

nohup nice java -jar $destFile --server.port=$serverPort --spring.profiles.active=$preferProp &

echo "$output""$properties"" &"

fi

echo " "

}

watch(){

tail -f $dstLogFile |

while IFS= read line

do

echo "$line"

if [[ "$line" == *"$whatToFind"* ]]

then

echo $msgAppStarted

pkill? tail

fi

done

}

### FUNCTIONS CALLS

#####################

# Use Example of this file. Args: project name | server port | configuration file: application.properties

# BUILD_ID=dontKillMe /path/to/this/file/spring-boot-jenkins.sh iplay 8081 application-run.properties

# 1 - stop server on port ...

stopServer

# 2 - delete destinations folder content

deleteFiles

# 3 - copy files to deploy dir

copyFiles

# 4 - start server

run

# 5 - watch loading messages until? ($whatToFind) message is found

#watch

注意:此代碼在linux下運行可能會產(chǎn)生格式問題,可以在vim中設(shè)置一下:

windows中編輯了sh文件后 放在linux中 使用vi轉(zhuǎn)碼

:set fileformat=unix

shell 代碼參考:github.com/rcoli/spring-boot-jenkins

截圖7,8來自:blog.csdn.net/xlgen157387/article/details/72852428

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

推薦閱讀更多精彩內(nèi)容