stage('NPM Build') { steps { script { echo "代码编译打包" dir('front/') { sh 'npm install --unsafe-perm=true --allow-root' sh 'npm run build' } } } } |
stage('Docker Build') { steps { script { echo "天生镜像" def pName = "${projectName}" def list = pName.split('_') dockerName = list[0] taget_image="${dockerName}:${tag}" sh "docker build --build-arg app=${appName} -t ${taget_image} ." sh "docker tag ${taget_image} ${harbor_server}/${harbor_project}/${dockerName}" sh "docker tag ${taget_image} ${harbor_server}/${harbor_project}/${dockerName}:${commitHash}" } } } |
FROM php:5.6-apache MAINTAINER winyeahs RUN apt-get update RUN apt-get install -y libwebp-dev libfreetype6-dev libmcrypt-dev libjpeg-dev libpng-dev zlib1g-dev RUN docker-php-ext-configure gd --with-webp-dir=/usr/include/webp --with-jpeg-dir=/usr/include --with-png-dir=/usr/include --with-freetype-dir=/usr/include/freetype2 RUN docker-php-ext-install gd RUN docker-php-ext-install mysql COPY ./back /var/www/html/ COPY ./front/dist /var/www/html/ RUN chmod -R 777 /var/www/html/gthmmc/template_c/ RUN chmod -R 777 /var/www/html/gthmmc/cache/ RUN service apache2 restart |
stage('Horbor Upload') { steps { script { docker_path="${WORKSPACE}" echo "登录Harbor" sh "cd ${docker_path}" sh "docker login ${harbor_server} -u ${harbor_account} -p ${harbor_password}" echo "天生镜像并推送到Harbor" def pName = "${projectName}" def list = pName.split('_') dockerName = list[0] sh "docker push ${harbor_server}/${harbor_project}/${dockerName}:latest" sh "docker push ${harbor_server}/${harbor_project}/${dockerName}:${commitHash}" echo "删除本地镜像" sh "docker rmi -f \$(docker images|grep ${dockerName}|grep ${tag}|awk '{print \$3}'|head -n 1)" } } } |
stage('Helm Deploy') { steps { echo "摆设到K8s" script { //根据不同情况将服务摆设到不同的namespace下,这里使用分支名称 def pName = "${projectName}" def list = pName.split('_') dockerName = list[0] sh "/usr/local/bin/helm repo update" sh "/usr/local/bin/helm package chart" sh "/usr/local/bin/helm push *.tgz mychart -u ${harbor_account} -p ${harbor_password}" sh "/usr/local/bin/helm upgrade ${dockerName} chart/ --set commitHash=${commitHash}" } } } |
post { success { emailext ( subject: "项目构建成功: 任务 '${env.JOB_NAME} [${env.BUILD_NUMBER}]'", body: """ 任务构建成功: 任务 '${env.JOB_NAME} [${env.BUILD_NUMBER}]': Check console output at "${env.JOB_NAME} [${env.BUILD_NUMBER}]" """, to: "[email protected]", from: " xxxxxx @qq.com" ) } failure { emailext ( subject: "项目构建失败: 任务 '${env.JOB_NAME} [${env.BUILD_NUMBER}]'", body: """ 项目构建失败: 任务 '${env.JOB_NAME} [${env.BUILD_NUMBER}]': Check console output at "${env.JOB_NAME} [${env.BUILD_NUMBER}]" """, to: " xxxxxx @qq.com", from: " xxxxxx @qq.com" ) } } |
post { success { ftpPublisher alwaysPublishFromMaster: false, continueOnError: true, failOnError: false, masterNodeName: '', paramPublish: null, publishers: [[ configName: 'amobiletour_c', transfers: [[ asciiMode: false, cleanRemote: false, excludes: '', flatten: false, makeEmptyDirs: false, noDefaultExcludes: false, patternSeparator: '[, ]+', remoteDirectory: '', remoteDirectorySDF: false, removePrefix: 'back', sourceFiles: 'back/**' ]], usePromotionTimestamp: false, useWorkspaceInPromotion: false, verbose: false ]] ftpPublisher alwaysPublishFromMaster: false, continueOnError: true, failOnError: false, masterNodeName: '', paramPublish: null, publishers: [[ configName: 'amobiletour_c', transfers: [[ asciiMode: false, cleanRemote: false, excludes: '', flatten: false, makeEmptyDirs: false, noDefaultExcludes: false, patternSeparator: '[, ]+', remoteDirectory: '', remoteDirectorySDF: false, removePrefix: 'front/dist', sourceFiles: 'front/dist/**' ]], usePromotionTimestamp: false, useWorkspaceInPromotion: false, verbose: false ]] } } |
欢迎光临 创意电子 (https://wxcydz.cc/) | Powered by Discuz! X3.4 |