1 安装Jenkins
    2 配置jenkins

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