0%

Jenkins-创建freestyle风格项目

Jenkins-创建freestyle风格项目

创建第一个Job

  1. 新建Item

  2. 输入名称、选择Job类型

  3. 配置Job,

    共六部分:通用源码管理构建触发器构建环境构建构建后操作

    常用操作:

    通用:配置参数话构建

    源码管理:配置代码仓库地址(git或svn)

    构建触发器:配置GitLab的webhook自动触发

    构建环境:Delete workspace before build starts

    构建:shell脚本或者bat脚本执行任务

    构建后操作:邮件通知

  4. 参数化构建

  5. Git地址

  6. 触发器

  7. 构建-shell脚本

  8. 保存退出

  9. 构建

  10. 查看构建状态

  11. 查看构建日志

实战分享

需求:
  1. 项目名称为vdam-web-vip
  2. 此job会根据环境不同确定git分支
  3. git clone后编译安装nodejs模块
  4. 构建docker镜像,push到镜像仓库
  5. 触发应用更新
部署:
  1. 创建自由风格项目

  2. 名称输入vdam-web-vip

  3. 开启参数化构建

  4. 配置构建shell

    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
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    set -e

    ## 确定 default.conf 和 nginx.conf文件存在

    Time=`date +%Y%m%d%H%M%S`
    WorkDir=`pwd`

    if [[ ${Scope} == "测试环境" ]]; then
    Branch="release"
    ScopeName="test"
    JavaServiceDomain="test-vdam-gateway-service.fotomore.com"
    fi
    if [[ ${Scope} == "预发环境" ]]; then
    Branch="master"
    ScopeName="pre"
    JavaServiceDomain="vdam-gateway-service1.fotomore.com"
    fi
    if [[ ${Scope} == "生产环境" ]]; then
    Branch="master"
    ScopeName="pro"
    JavaServiceDomain="vdam-gateway-service.fotomore.com"
    fi

    rm -rf vdam-web
    mkdir -p vdam-web
    cd vdam-web
    git clone -b ${Branch} git@git.vcg.com:vdam/vue-vip-2019.git
    git clone -b ${Branch} git@git.vcg.com:vdam/vue-admin.git
    git clone -b ${Branch} git@git.vcg.com:vdam/vue-saas.git
    git clone -b ${Branch} git@git.visualchina.com:vdam/vue-vip-upload.git

    cd vue-vip-upload
    sed -i "s/vdam-gateway.vcg.com/$JavaServiceDomain/g" setBaseUrl.ts
    sed -i "s/vdam-gateway-service.fotomore.com/$JavaServiceDomain/g" setBaseUrl.ts
    sed -i "s/vdam-gateway.fotomore.com/$JavaServiceDomain/g" setBaseUrl.ts
    sed -i "s/vdam-gateway-service.caf79ccb624f24a5cabd1de8623b2e617.cn-beijing.alicontainer.com/$JavaServiceDomain/g" setBaseUrl.ts

    npm install --registry https://registry.npm.taobao.org
    npm run build
    mv dist ../
    cd ..
    mv dist upload

    cd vue-vip-2019
    sed -i "s/vdam-gateway.vcg.com/$JavaServiceDomain/g" setBaseUrl.ts
    sed -i "s/vdam-gateway-service.fotomore.com/$JavaServiceDomain/g" setBaseUrl.ts
    sed -i "s/vdam-gateway.fotomore.com/$JavaServiceDomain/g" setBaseUrl.ts
    sed -i "s/vdam-gateway-service.caf79ccb624f24a5cabd1de8623b2e617.cn-beijing.alicontainer.com/$JavaServiceDomain/g" setBaseUrl.ts

    npm install --registry https://registry.npm.taobao.org
    npm run build
    mv dist ../
    cd ..
    mv dist vip

    cd vue-admin
    sed -i "s/vdam-gateway.vcg.com/$JavaServiceDomain/g" src/config/index.js
    sed -i "s/vdam-gateway-service.fotomore.com/$JavaServiceDomain/g" src/config/index.js
    sed -i "s/vdam-gateway.fotomore.com/$JavaServiceDomain/g" src/config/index.js
    sed -i "s/vdam-gateway-service.caf79ccb624f24a5cabd1de8623b2e617.cn-beijing.alicontainer.com/$JavaServiceDomain/g" src/config/index.js

    npm install --registry https://registry.npm.taobao.org
    npm run build
    mv dist ../
    cd ..
    mv dist admin

    cd vue-saas
    sed -i "s/test-vdam.gateway.vcg.com/$JavaServiceDomain/g" src/config/index.js
    sed -i "s/vdam-gateway.vcg.com/$JavaServiceDomain/g" src/config/index.js
    sed -i "s/vdam-gateway-service.fotomore.com/$JavaServiceDomain/g" src/config/index.js
    sed -i "s/vdam-gateway.fotomore.com/$JavaServiceDomain/g" src/config/index.js
    sed -i "s/vdam-gateway-service.caf79ccb624f24a5cabd1de8623b2e617.cn-beijing.alicontainer.com/$JavaServiceDomain/g" src/config/index.js

    npm install --registry https://registry.npm.taobao.org
    npm run build
    mv dist ../
    cd ..
    mv dist saas

    rm -rf vue-vip
    rm -rf vue-admin
    rm -rf vue-saas

    cd ..

    tar zcf vdam-web-vip.tar.gz vdam-web/

    # cp vdam-web-vip.tar.gz /jenkins/vcgapp/vdam-web-vip/vdam-web-vip.tar.gz-${Time}

    cat > Dockerfile <<EOF
    FROM nginx
    MAINTAINER hongye.zhao@vcg.com
    ADD vdam-web-vip.tar.gz /usr/share/nginx/html/
    ADD nginx.conf /etc/nginx/nginx.conf
    ADD default.conf /etc/nginx/conf.d/
    RUN chmod -R 777 /usr/share/nginx/html/
    EOF

    docker build -t registry-vpc.cn-beijing.aliyuncs.com/vcg/vdam-web-vips:${ScopeName} .
    docker build -t registry-vpc.cn-beijing.aliyuncs.com/vcg/vdam-web-vips:${ScopeName}-$Time .
    docker push registry-vpc.cn-beijing.aliyuncs.com/vcg/vdam-web-vips:${ScopeName}
    docker push registry-vpc.cn-beijing.aliyuncs.com/vcg/vdam-web-vips:${ScopeName}-$Time
    docker rmi -f registry-vpc.cn-beijing.aliyuncs.com/vcg/vdam-web-vips:${ScopeName}
    docker rmi -f registry-vpc.cn-beijing.aliyuncs.com/vcg/vdam-web-vips:${ScopeName}-$Time

    if [[ ${Scope} == "测试环境" ]]; then
    curl https://cs.console.aliyun.com/hook/trigger?token=eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJjbHVzdGVySWQiOiJjYWY3OWNjYjYyNGYyNGE1Y2FiZDFkZTg2MjNiMmU2MTciLCJpZCI6IjM5NTI2In0.S9KkUgPkymqsc1xclUHFo9zFyd_iLMrKxxEbsPB06lajpw_YSm7aOXAonq_olgP0SxmL6ydiDE5Bu3LuAXjhMCkojXQx4FlnH8uoaBOr2fT9e_RL-4LCGSQLDvoOFqQQ1csBfPi2UpT6oDh_KkxvaYoF7kqvTmpClF2XQO9X9f4
    #curl https://cs.console.aliyun.com/hook/trigger?token=eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJjbHVzdGVySWQiOiJjYWY3OWNjYjYyNGYyNGE1Y2FiZDFkZTg2MjNiMmU2MTciLCJpZCI6IjMyNzQ0In0.afM-iP1cZUVBDdIefzca6SJyIfFBPO3hqcC0HgrJPcaQLkvmFQYuHAgF6OHKgdHLa0rErRvcKgq1t_6g4DhBiql5EN9qQYAiAKEwXTpfc-0tiNfZg4w2Z4mybg-MeiduZCD0Reh1hUy-jdNNg58poR-IeKJZRhT3IlmfIp4Ssis
    fi
    if [[ ${Scope} == "预发环境" ]]; then
    curl https://cs.console.aliyun.com/hook/trigger?token=eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJjbHVzdGVySWQiOiJjMmFiNDFlZWE0YjgxNDNlZmEwMzg3OWZiNDlhOWEyODIiLCJpZCI6IjM5NTI1In0.nwNJTY-9jPhbnVe1_4fTUuCXPd5JlkRlvGgQC8GD-u1qBqsousj8wsO65s6xhksW0h1PBPVnTn8QelwgCLMLyIvN8Pv_H7uB2x4tGHudZHjrPxKURgU6cwH4SnXhd3VYOdfd-Qc3sMKAe9aG_HoKwQoC2Zj2yT3kTQEB7j7Mlv0
    #curl https://cs.console.aliyun.com/hook/trigger?token=eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJjbHVzdGVySWQiOiJjMmFiNDFlZWE0YjgxNDNlZmEwMzg3OWZiNDlhOWEyODIiLCJpZCI6IjM3MDcyIn0.Dxx3lVTAysaRBtI6jcDLMm0M0Yh239eUznxq4dpUIIjhDsKLlgtN-UJt0TIBOmAucj8XnBjI_T-mX7hy6WrHH8bKREyMz6cWrGutfBQqNYQ2j-HyScP-Q8tsqO1q4XZuuS9__BB2-mDoN0xqqFUAAITkDkmw702rfRpbIolvNu4
    fi
    if [[ ${Scope} == "生产环境" ]]; then
    echo ""
    curl https://cs.console.aliyun.com/hook/trigger?token=eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJjbHVzdGVySWQiOiJjNDY0MTNjYjEzYmIzNDkwZGEzZTQ5NWU0MjY0ZjZkMTkiLCJpZCI6IjM3MTkzIn0.HJfnm1ujwLRYnQpsRpiXLErKi2gE_glnZBcss9c2zmHGv-_Gcl6vYLRPdmnPpvcU2cVkuKgExHUUFGdNqzkKDEeFu8lBez9c2gCWi7l81KNAFhsgtTIEm8YRpi9p92kIsutjD_AEj6UuY_jy58nvIWGeXRtuYAaWJGXFQ6B5ItE
    fi

  5. 保存退出

  6. 参数化构建

  7. 验证ok