Here is the script with comments:
#!/bin/bash
# Connection ID (username)
CONID=root
# Connection key (password)
CONKEY=deploy123456
# Working directory
WORK\_DIR=/opt/demo
# Application JAR file name
APP\_JAR=demo.jar
# Git repository URL
REPO\_URL=http://gitlab.teet.com/test.git
# Git pull
#git pull
# Go to working directory
cd $WORK\_DIR
# Clone git repository
git clone $REPO\_URL .
# Go to demo directory
cd /opt/demo
# Pull latest changes from Git using expect (auto enter username and password)
expect -c "spawn git pull origin; expect \*"Username\*" { send \\"${CONID}\\n\\"; exp\_continue } \*"Password\*" { send \\"${CONKEY}\\n\\" }; interact"
# Maven build
mvn clean package -Dmaven.pro.skip=true -P pro
# Deploy
ps -ef| grep demo |grep -v grep | awk '{print $2}' |xargs kill -9
# Run jar file
nohup java -jar /opt/demo/target/$APP\_JAR > demo.log 2>&1 &