shell脚本git拉取代码并编译打包发送到部署服务器

本文介绍了如何通过shell脚本实现自动化流程,包括从git仓库拉取最新代码,执行Java项目的编译,生成jar包,并将其发送到部署服务器进行更新,以提升运维效率。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#!/bin/bash

stty erase ^H
read -e -p 'Please enter the code place directory:'  FOLDER
while [ -z $FOLDER ]
      do
      read -e  -p 'file directory is empty, enter a new one:'  FOLDER
done

if [ ! -d $FOLDER ]
   then
        mkdir $FOLDER
        echo "Creating a File Directory"
fi
cd $FOLDER


read -e -p 'Please enter the git address:'  URL
while [ -z $URL ]
     do
     read -e -p 'Git address is empty. Please enter it again:'  URL
done


read -e -p 'Please enter the remote repository alias (origin by default):'  NAME
if [ -z $NAME ]
   then
   NAME='origin'
fi


read -e -p 'Please enter the branch name (master by default) :'  BRANCH
if [ -z $BRANCH ]
   then
   BRANCH='master'
fi

if ! [ -x "$(command -v git)" ]
    then
    echo 'Start installing Git'
    apt-get install -y  git
fi


#pull
result=$(git clone -b $BRANCH $URL)
if [ $? -ne 0 ]; then
    echo $result
    exit 1
else
    echo "git clone success"
fi


if ! [ -x "$(command -v mvn)" ]
    then
    echo 'Start installing maven'
    apt-get install -y maven
fi


read -e -p 'Please enter the project compilation directory:'  PROJECT

project_result=$(cd $PROJECT)
if [ $? -ne 0 ]; then
    echo $project_result
    exit 1
else
    echo 'Begin to compile'
fi
cd $PROJECT
mvn clean
mvn package

echo "maven compile success"

read -e -p 'Please enter the SCP port number:' PORT

read -e -p 'Please enter the remote file target (username@ip:file):' REMOTE_FILE

scp -P $PORT target/xxxx.jar target/xxx.jar $REMOTE_FILE

cd ../
rm -rf $PROJECT

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值