jenkins部署php程序
# 配置需要发布的项目参数
# 配置源码管理
# 配置构建环境
# 配置需要执行的shell
rsync -avzu --partial --delete -e "ssh -p 22" ${WORKSPACE}/commands ${WORKSPACE}/components ${WORKSPACE}/controllers ${WORKSPACE}/forms ${WORKSPACE}/models ${WORKSPACE}/helpers jenkinstransfer@xxxxx:/workspace/tmp/ --exclude ".gitignore"
1
# 配置构建后的参数
#!/bin/bash
if [ "$deploy" = "update" ];then
sudo /workspace/sh/update.sh ${BUILD_VERSION}
else
sudo /workspace/sh/rollback.sh ${ROLLBACK_VERSION}
fi
1
2
3
4
5
6
2
3
4
5
6
脚本如下
update.sh
#!/bin/bash
BUILD_VERSION=$1
cd /workspace/sh/backup
tar -czf ${BUILD_VERSION}.tar.gz /workspace/test/commands \
/workspace/test/components \
/workspace/test/controllers \
/workspace/test/forms \
/workspace/test/models \
/workspace/test/helpers
if [ "$?" -eq "0" ];then
echo "备份${BUILD_VERSION}.tar.gz成功"
echo "以下执行本地更新"
fi
rsync -a /workspace/tmp/ /workspace/test/ | tee /workspace/sh/logs/update-`date +"%Y%m%d-%H%M%S"`.log
chown -R root:root /workspace/test
if [ "$?" -eq "0" ];then
echo "更新成功"
else
echo "更新失败"
fi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
rollback.sh
#!/bin/bash
ROLLBACK_VERSION=`echo $1|col -b`
cd /workspace/sh/backup/
if [ -s ${ROLLBACK_VERSION}.tar.gz ];then
echo "解压缩文件:${ROLLBACK_VERSION}.tar.gz"
tar -xf ${ROLLBACK_VERSION}.tar.gz
fi
if [ "$?" -eq "0" ];then
echo "解压成功"
else
echo "error:解压失败" >&2
exit 1
fi
rsync -av /workspace/sh/backup/workspace/test/* /workspace/test/
if [ "$?" -eq "0" ];then
echo "回滚成功"
else
echo "error:回滚失败" >&2
exit 1
fi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
上次更新: 2023/06/25, 21:59:56