1 安装Jenkins
2 配置jenkins
#!/bin/bash
set -xe
## 根据 environment 决定使用哪一个 branch
if [[ -z "$revision" ]]; then
## 修改 branch 值来自定义每种环境对应的分支
case $environment in
develop ) branch=master;;
qa ) branch=master;;
stage ) branch=master;;
production ) branch=master;;
* ) branch=master;;
esac
fi
## 切换到目标代码版本
ref=$(echo $(git rev-parse -q --verify ${revision:-$branch}))
ref=${ref:-$(git rev-parse -q --verify origin/${revision:-$branch})}
if [[ -z "$ref" ]]; then
echo "无效的 revision 或 branch。"
exit 1
fi
git checkout -f $ref
echo '$ref'
## 安装依赖、构建
npm install --registry=https://registry.npm.taobao.org/
npm run build:${environment}
## 打包构建产物,输出包的 url
package_file="${app_name}.${environment}.tar.gz"
package_url="${JENKINS_URL}userContent/${package_file}"
tar -czvf ~/userContent/${package_file} dist/
## 非生产环境直接部署
mq-deployer-send \
--uri amqp://jenkins:jenkins@域名:端口号/%2F \
--exchange jenkins-v2 \
--router support.${app_name}.${environment} \
"{\"packageUrl\": \"${package_url}\"}"