jenkins如何与shell脚本结合使用

一、首先创建项目:

image

底下这两个一个是自由风格项目,一个是maven项目

 

image

 

二、创建好之后点击项目

image

 

image

 

image

 

image

 

image

 

完成以上操作,在构建的时候,就会执行此处的shell脚本!

 

shell脚本如下(此处根据自己业务需求写自己的shell脚本):

#!/bin/bash
#自动化部署前端脚本
GREEN='\033[0;32m'
NC='\033[0m' # 重置颜色
TIMESTAMP=$(date +"%Y%m%d_%H%M%S")
backup_hello_name="hello_$TIMESTAMP"

mkdir "/tmp/$backup_hello_name"
cp -r /opt/nginx/html/test/hello/* /tmp/$backup_hello_name/
echo -e "${GREEN}备份/test/hello/成功${NC}"

rm -rf /opt/nginx/html/test/hello/*
echo -e "${GREEN}删除/test/hello/成功${NC}"


cp -r ./spa/* /opt/nginx/html/test/hello/

echo -e "${GREEN}复制最新前端文件至/test/hello/成功${NC}"


echo -e "${GREEN}complete!sucess!You're the best!${NC}"

 

posted @ 2025-09-19 10:32  少年强则国强  阅读(10)  评论(0)    收藏  举报