假如有 开发 测试 预发 生产1 生产2服务器
.gitlab-ci.yml
stages:
- deploy
- test
- release
- master
构建开发环境:
stage: deploy
script:
- /data-ci/eatjoys-front.sh
only:
- develop
tags:
- my-erp
构建测试环境:
stage: test
script:
- /data-ci/eatjoys-front.sh
only:
- test
tags:
- my-erp
构建预发环境:
stage: release
script:
- /data-ci/eatjoys-front.sh
only:
- release
tags:
- my-erp
构建生产环境:
stage: master
script:
- /data-ci/eatjoys-front.sh
only:
- master
tags:
- my-erp
[root@sannian data-ci]# vim eatjoys-front.sh
#!/bin/sh
#env
if [ $CI_BUILD_REF_SLUG = 'develop' ]; then
projectdir="/work/front/${CI_PROJECT_NAME}"
echo
echo
echo "-----------------------------------------------------------------------"
echo "发布 主机: $i 项目: $CI_PROJECT_NAME "
cd $CI_PROJECT_DIR
# yarn
# npm run
echo scp -r $CI_PROJECT_DIR/* root@47.99.89.247:${projectdir}/
scp -r $CI_PROJECT_DIR/* root@47.99.89.247:${projectdir}/
if [ $? = 0 ]; then
echo "mvn 构建成功...."
else
echo "mvn 构建失败...."
exit 100
fi
echo
echo
fi
if [ $CI_BUILD_REF_SLUG = 'test' ]; then
projectdir="/work/front/${CI_PROJECT_NAME}"
echo
echo
echo "-----------------------------------------------------------------------"
echo "发布 主机: $i 项目: $CI_PROJECT_NAME "
cd $CI_PROJECT_DIR
# yarn
# npm run
echo scp -r $CI_PROJECT_DIR/* root@47.99.89.247:${projectdir}/
scp -r $CI_PROJECT_DIR/* root@47.99.89.247:/work/front/my-erp-test/
if [ $? = 0 ]; then
echo "mvn 构建成功...."
else
echo "mvn 构建失败...."
exit 100
fi
echo
echo
fi
if [ $CI_BUILD_REF_SLUG = 'release' ]; then
projectdir="/work/front/${CI_PROJECT_NAME}"
echo
echo
echo "-----------------------------------------------------------------------"
echo "发布 主机: $i 项目: $CI_PROJECT_NAME "
cd $CI_PROJECT_DIR
# yarn
# npm run
echo scp -r $CI_PROJECT_DIR/* root@47.99.89.247:/work/front/my-erp-release/
scp -r $CI_PROJECT_DIR/* root@47.99.89.247:/work/front/my-erp-release/
if [ $? = 0 ]; then
echo "mvn 构建成功...."
else
echo "mvn 构建失败...."
exit 100
fi
echo
echo
fi
if [ $CI_BUILD_REF_SLUG = 'master' ]; then
projectdir="/work/front/${CI_PROJECT_NAME}"
echo
echo
echo "-----------------------------------------------------------------------"
echo "发布 主机: $i 项目: $CI_PROJECT_NAME "
cd $CI_PROJECT_DIR
# yarn
# npm run
echo scp -r $CI_PROJECT_DIR/* root@47.99.89.247:${projectdir}/
scp -r $CI_PROJECT_DIR/* root@47.99.89.247:/work/front/my-erp-master/
if [ $? = 0 ]; then
echo "mvn 构建成功...."
else
echo "mvn 构建失败...."
exit 100
fi
echo
echo
fi