zoukankan      html  css  js  c++  java
  • jenkins pipeline docker 发布项目

    环境:

    192.168.100.148 开发环境

    192.168.100.140 jenkins 服务器

    harbor.zong.com 镜像仓库

     

    1.拉取代码

    2.构建

    3.sonarqube 代码扫描质检

    4.构建生成镜像推送仓库

    5.部署到开发环境服务器

    6.成功或失败钉钉通知群内

    pipeline {
        agent any
        
        
        environment {
            _version = sh(script: "echo `date '+%Y%m%d%H%M%S'`", returnStdout: true).trim()
            DINGDING_ROBOT_URL = 'https://oapi.dingtalk.com/robot/send?access_token=aa67b55f25245c319aedd6efe5d20d81ac1cfe6e858c15d20914e8fd26a4e6ac'
            BUILD_USER_ID = ""
            BUILD_USER = ""
            BUILD_USER_EMAIL = ""
            ChangeLog = ""
            Docker_mg_Name = "47.99.1.15:81/192.168.100.148/"         //Harbor Image warehouse address 
            Esl_app_1 = "esl_app_1" 
            BRANCH = "dev_3.5"
        }
    
    
    
        stages {
    
           stage ("Time stamp") { //time stamp
                steps {
                    echo "${_version}"
    
                }
    
            }
      
            
    
    
            stage('Pull code') {          //get project code from repo
                steps {
                      checkout([$class: 'GitSCM', branches: [[name: "*/${BRANCH}"]], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[url: 'http://192.168.100.140/esl_backend/zk.git']]])
    
                }
            }
        
    
    
            stage('structure') {        //exec mvn cmd
                steps {
                    withMaven(jdk: 'jdk', maven: 'maven') {
                       sh 'mvn clean package -DskipTests ' 
                    }
                }
            }
           stage('Code scanning') {
                steps {
                    echo "starting codeAnalyze with SonarQube......"
                    sh "mvn sonar:sonar -Dsonar.projectName=148-服务端  -Dsonar.host.url=http://192.168.100.118:9000 -Dsonar.login=e6e89488da1d3051006be436a4899d4209771851"
                }
            }
    
    
    
            stage('Building a mirror image') {         //move jar file into project_dir
                steps {
                      sh "docker build -t ${Docker_mg_Name}${Esl_app_1}:${BRANCH} ."  //Building a mirror image
                      sh "docker login 47.99.1.15:81 -uadmin -pZkongNB1234"                 //Log in to image warehouse
                      sh "docker push ${Docker_mg_Name}${Esl_app_1}:${BRANCH}"       // Push to remote image warehouse
                      sh "docker rmi ${Docker_mg_Name}${Esl_app_1}:${BRANCH}"         //Delete local mirror 
                      
                }
            }
    
            stage('Running image'){ //pull run docker images
               steps {
                 sshPublisher(publishers: [sshPublisherDesc(configName: '148', transfers: [sshTransfer(cleanRemote: false, excludes: '', execCommand: "bash /server/scripts/deploy.sh ${BRANCH}", execTimeout: 120000, flatten: false, makeEmptyDirs: false, noDefaultExcludes: false, patternSeparator: '[, ]+', remoteDirectory: '', remoteDirectorySDF: false, removePrefix: '', sourceFiles: '')], usePromotionTimestamp: false, useWorkspaceInPromotion: false, verbose: false)])           }
           }
    
    
        }
    
    
    
    post {
            //Build failure notification
    
            failure {
              script {
                     dingtalk (
                            robot: '31ca2fb0-964a-468f-81dd-edf521f78446',
                            type: 'MARKDOWN',
                            title: "项目构建信息",
                            text: [
                                '### 项目构建信息',
                                ">- job名称:    **${JOB_NAME}**",
                                ">- 持续时间:    **${currentBuild.durationString}**",
                                ">- 当前分支:    **${env.BRANCH}**",
                                ">- 构建发起:    **${BUILD_USER}**",
                                ">- 构建结果:   **构建失败❌*",
                                ">- 构建日志:    [点击查看详情](${env.BUILD_URL}console)",
                               // ">- 更新记录:    **${ChangeLog}**",
                                 
                                       
                            ],
     
                            at: [
                              '所有人'
                            ]
                        )
              }
     
            }
    
            //Build success notification
    
            success {
            wrap([$class: 'BuildUser']) {
                       script {
                           BUILD_USER_ID = "${env.BUILD_USER_ID}"
                           BUILD_USER = "${env.BUILD_USER}"
                           BUILD_USER_EMAIL = "${env.BUILD_USER_EMAIL}"
                           ChangeLog = "${env.ChangeLog}"
                       }
                    }
                dingtalk (
                    robot: '31ca2fb0-964a-468f-81dd-edf521f78446',
                            type: 'MARKDOWN',
                            title: "项目构建信息",
                            text: [
                                '### 项目构建信息',
                                ">- job名称:    **${JOB_NAME}**",
                                ">- 持续时间:    **${currentBuild.durationString}**",
                                ">- 当前分支:    **${env.BRANCH}**",
                                ">- 构建发起:    **${BUILD_USER}**",
                                ">- 构建结果:   **构建成功 ✅**",
                                ">- 构建日志:    [点击查看详情](${env.BUILD_URL}console)",
                               // ">- 更新记录:    **${ChangeLog}**",
                                 
                                       
                            ],
     
                            at: [
                              '所有人'
                            ]
                        )
                    }
                }
    
    }
    

      

  • 相关阅读:
    MySQL-基本sql命令
    Java for LeetCode 203 Remove Linked List Elements
    Java for LeetCode 202 Happy Number
    Java for LeetCode 201 Bitwise AND of Numbers Range
    Java for LeetCode 200 Number of Islands
    Java for LeetCode 199 Binary Tree Right Side View
    Java for LeetCode 198 House Robber
    Java for LeetCode 191 Number of 1 Bits
    Java for LeetCode 190 Reverse Bits
    Java for LeetCode 189 Rotate Array
  • 原文地址:https://www.cnblogs.com/sseban/p/14821885.html
Copyright © 2011-2022 走看看