jenkins pipeline流水线

1.华东预发前端发布

 

 

 

 

 

 

地址:http://192.168.100.140:8080/

此次jenkins发布主要依赖pipeline 声明式语法

 

v1版本发布主要更新拉取代码构建发布

pipeline {

    agent any

 

    stages {

        

        stage('checkout') {

            steps {

                checkout([$class: 'GitSCM', branches: [[name: '*/masterv3.3']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[url: 'http://192.168.100.140/esl_front/ESL-manager.git']]])

            }

        }

        stage('BUILD') {

            steps {

                sh 'npm run build'

               

            }

        }

        stage('Deploy') {

            steps {

                sshPublisher(publishers: [sshPublisherDesc(configName: '华东(121.40.124.33)', transfers: [sshTransfer(cleanRemote: false, excludes: '', execCommand: '', execTimeout: 120000, flatten: false, makeEmptyDirs: false, noDefaultExcludes: false, patternSeparator: '[, ]+', remoteDirectory: '/etc/nginx/html/build/', remoteDirectorySDF: false, removePrefix: '', sourceFiles: 'dist/**')], usePromotionTimestamp: false, useWorkspaceInPromotion: false, verbose: false)])

            }

        }

    }

}

 

1.1 华东前端发布

pipeline {

    agent any

    environment {

    DINGDING_ROBOT_URL = 'https://oapi.dingtalk.com/robot/send?access_token=aa67b55f25245c319aedd6efe5d20d81ac1cfe6e858c15d20914e8fd26a4e6ac'

    BRANCH="master3.3"

    BUILD_USER_ID = ""

    BUILD_USER = ""

    BUILD_USER_EMAIL = ""

    ChangeLog = ""

        

    }

    stages {

        //拉取代码

        stage('checkout') {

            steps {

                checkout([$class: 'GitSCM', branches: [[name: '*/masterv3.3']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[url: 'http://192.168.100.140/esl_front/ESL-manager.git']]])

            }

        }

        

        

        

        //构建

        stage('BUILD') {

            steps {

                sh 'npm run build'

               

            }

        }

        

        

        //部署

        stage('Deploy') {

            steps {

                sshPublisher(publishers: [sshPublisherDesc(configName: '华东(121.40.124.33)', transfers: [sshTransfer(cleanRemote: false, excludes: '', execCommand: '', execTimeout: 120000, flatten: false, makeEmptyDirs: false, noDefaultExcludes: false, patternSeparator: '[, ]+', remoteDirectory: '/etc/nginx/html/build/', remoteDirectorySDF: false, removePrefix: '', sourceFiles: 'dist/**')], usePromotionTimestamp: false, useWorkspaceInPromotion: false, verbose: false)])

            }

        }

    }

    

    

    

    // stages 所有任务执行后触发post

    post {

        //构建失败通知

        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: [

                          '所有人'

                        ]

                    )

          }

 

        }

        //构建成功通知

        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: [

                          '所有人'

                        ]

                    )

        }

    }

    

}

 

 

1.2 华东后端

pipeline {

    agent any

    environment {

    DINGDING_ROBOT_URL = 'https://oapi.dingtalk.com/robot/send?access_token=aa67b55f25245c319aedd6efe5d20d81ac1cfe6e858c15d20914e8fd26a4e6ac'

    BRANCH="master3.3"

    BUILD_USER_ID = ""

    BUILD_USER = ""

    BUILD_USER_EMAIL = ""

    ChangeLog = ""

         

    }

 

    stages {

         

        

        stage('checkout') {

            steps {

                  checkout([$class: 'GitSCM', branches: [[name: '*/dev_3.3']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[url: 'http://192.168.100.140/esl_backend/zk.git']]])

 

            }

        }

        

        //构建

        stage('Build') {

            steps {

                withMaven(jdk: 'jdk', maven: 'maven') {

                   sh 'mvn clean package -DskipTests'

                }

            }

        }

        

        //同步jar包到服务器  start

        stage('Push package') {

            steps {

                  sshPublisher(publishers: [sshPublisherDesc(configName: '华东(121.40.124.33)', transfers: [sshTransfer(cleanRemote: false, excludes: '', execCommand: '/usr/local/esl/start.sh', execTimeout: 120000, flatten: false, makeEmptyDirs: false, noDefaultExcludes: false, patternSeparator: '[, ]+', remoteDirectory: '/usr/local/esl', remoteDirectorySDF: false, removePrefix: 'target', sourceFiles: 'target/*')], usePromotionTimestamp: false, useWorkspaceInPromotion: false, verbose: false)])

 

            }

        }

        

    }

    

      post {

        //构建失败通知

        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: [

                          '所有人'

                        ]

                    )

          }

 

        }

        //构建成功通知

        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: [

                          '所有人'

                        ]

                    )

        }

    }

}

 

2. 阿里云东京

    阿里云Jenkins任务主要构建master和back01-02机器、

   更新顺序 master→> back01→back02

   pipeline 流水线如下

2.1 阿里云东京-前端

pipeline {

    agent any

    environment {

    //DINGDING_ROBOT_URL 'https://oapi.dingtalk.com/robot/send?access_token=aa67b55f25245c319aedd6efe5d20d81ac1cfe6e858c15d20914e8fd26a4e6ac'

    BRANCH="shantian"

    BUILD_USER_ID = ""

    BUILD_USER = ""

    BUILD_USER_EMAIL = ""

    // ChangeLog = ""

         

    }

 

    stages {

        //GIT语法 

        //checkout:Check out from version control

        stage('checkout') {

            steps {

               checkout([$class: 'GitSCM', branches: [[name: '*/shantian']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[url: 'http://192.168.100.140/esl_front/ESL-manager.git']]])

            }

        }

        stage('BUILD') {

            steps {

                sh 'npm run build'

                

            }

        }

        //sshPublisher

        stage('Deploy') {

            steps {

              sshPublisher(publishers: [sshPublisherDesc(configName: '47.91.29.12', transfers: [sshTransfer(cleanRemote: false, excludes: '', execCommand: '', execTimeout: 120000, flatten: false, makeEmptyDirs: false, noDefaultExcludes: false, patternSeparator: '[, ]+', remoteDirectory: '/usr/share/nginx/html/build', remoteDirectorySDF: false, removePrefix: '', sourceFiles: 'dist/**')], usePromotionTimestamp: false, useWorkspaceInPromotion: false, verbose: false)])

            }

        }

    }

    

    post {

        //构建失败通知

        failure {

            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}"

                   }

                }

          script {

                 dingtalk (

                        robot: '31c097ba-4f71-4e9e-97f0-5f13e18c1ee2',

                        type'MARKDOWN',

                        title: "项目构建信息",

                        text: [

                            '### 项目构建信息',

                            ">- job名称:    **${JOB_NAME}**",

                            ">- 持续时间:    **${currentBuild.durationString}**",

                            ">- 当前分支:    **${env.BRANCH}**",

                            ">- 构建发起:    **${BUILD_USER}**",

                            ">- 构建结果:   **构建失败❌*",

                            ">- 构建日志:    [点击查看详情](${env.BUILD_URL}console)",

                           // ">- 更新记录:    **${ChangeLog}**",

                             

                                   

                        ],

 

                        at: [

                          '所有人'

                        ]

                    )

          }

 

        }

        //构建成功通知

        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: '31c097ba-4f71-4e9e-97f0-5f13e18c1ee2',

                        type'MARKDOWN',

                        title: "项目构建信息",

                        text: [

                            '### 项目构建信息',

                            ">- job名称:    **${JOB_NAME}**",

                            ">- 持续时间:    **${currentBuild.durationString}**",

                            ">- 当前分支:    **${env.BRANCH}**",

                            ">- 构建发起:    **${BUILD_USER}**",

                            ">- 构建结果:   **构建成功 ✅**",

                            ">- 构建日志:    [点击查看详情](${env.BUILD_URL}console)",

                            // ">- 流水线:       [点击查看详情](${env.JOB_URL}console)",

                           // ">- 更新记录:    **${ChangeLog}**",

                             

                                   

                        ],

 

                        at: [

                          '所有人'

                        ]

            )

        }

    }

}

2.2 阿里云东京后端发布

//山田mster 后端备份

 

 

pipeline {

    agent any

    environment {

    DINGDING_ROBOT_URL = 'https://oapi.dingtalk.com/robot/send?access_token=aa67b55f25245c319aedd6efe5d20d81ac1cfe6e858c15d20914e8fd26a4e6ac'

    BRANCH="shantian"

    BUILD_USER_ID = ""

    BUILD_USER = ""

    BUILD_USER_EMAIL = ""

    ChangeLog = ""

         

    }

 

    stages {

         

        

        stage('checkout') {

            steps {

                  checkout([$class: 'GitSCM', branches: [[name: '*/shantian']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[url: 'http://192.168.100.140/esl_backend/zk.git']]])

 

            }

        }

        

        //构建

        stage('Build') {

            steps {

                withMaven(jdk: 'jdk', maven: 'maven') {

                   sh 'mvn clean package -DskipTests'

                }

            }

        }

        

        //同步jar包到服务器  start

        stage('Push package') {

            steps {

               sshPublisher(publishers: [sshPublisherDesc(configName: '47.91.29.12', transfers: [sshTransfer(cleanRemote: false, excludes: '', execCommand: 'cd /usr/local/esl/ &&  docker-compose up -d --build', execTimeout: 120000, flatten: false, makeEmptyDirs: false, noDefaultExcludes: false, patternSeparator: '[, ]+', remoteDirectory: '/usr/local/esl/app', remoteDirectorySDF: false, removePrefix: 'target', sourceFiles: 'target/*')], usePromotionTimestamp: false, useWorkspaceInPromotion: false, verbose: false)])

 

            }

        }

 

         // 山田backup 01 start

        stage('push package Backup 01') {

            steps {

               sshPublisher(publishers: [sshPublisherDesc(configName: '8.209.252.82', transfers: [sshTransfer(cleanRemote: false, excludes: '', execCommand: 'cd /usr/local/esl/ &&  docker-compose up -d --build', execTimeout: 120000, flatten: false, makeEmptyDirs: false, noDefaultExcludes: false, patternSeparator: '[, ]+', remoteDirectory: '/usr/local/esl/app', remoteDirectorySDF: false, removePrefix: 'target', sourceFiles: 'target/*')], usePromotionTimestamp: false, useWorkspaceInPromotion: false, verbose: false)])

            }

 

        }

       

 

       //山田 backup 02 start

       stage('Push package Backup 02') {

            steps {

            sshPublisher(publishers: [sshPublisherDesc(configName: '47.91.31.80', transfers: [sshTransfer(cleanRemote: false, excludes: '', execCommand: 'cd /usr/local/esl/ &&  docker-compose up -d --build', execTimeout: 120000, flatten: false, makeEmptyDirs: false, noDefaultExcludes: false, patternSeparator: '[, ]+', remoteDirectory: '/usr/local/esl/app', remoteDirectorySDF: false, removePrefix: 'target', sourceFiles: 'target/*')], usePromotionTimestamp: false, useWorkspaceInPromotion: false, verbose: false)])

            }

       }

        

    }

 

    post {

        //构建失败通知

        failure {

            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}"

                   }

                }

          script {

                 dingtalk (

                        robot: '31c097ba-4f71-4e9e-97f0-5f13e18c1ee2',

                        type'MARKDOWN',

                        title: "项目构建信息",

                        text: [

                            '### 项目构建信息',

                            ">- job名称:    **${JOB_NAME}**",

                            ">- 持续时间:    **${currentBuild.durationString}**",

                            ">- 当前分支:    **${env.BRANCH}**",

                            ">- 构建发起:    **${BUILD_USER}**",

                            ">- 构建结果:   **构建失败❌*",

                            ">- 构建日志:    [点击查看详情](${env.BUILD_URL}console)",

                           // ">- 更新记录:    **${ChangeLog}**",

                             

                                   

                        ],

 

                        at: [

                          '所有人'

                        ]

                    )

          }

 

        }

        //构建成功通知

        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: '31c097ba-4f71-4e9e-97f0-5f13e18c1ee2',

                        type'MARKDOWN',

                        title: "项目构建信息",

                        text: [

                            '### 项目构建信息',

                            ">- job名称:    **${JOB_NAME}**",

                            ">- 持续时间:    **${currentBuild.durationString}**",

                            ">- 当前分支:    **${env.BRANCH}**",

                            ">- 构建发起:    **${BUILD_USER}**",

                            ">- 构建结果:   **构建成功 ✅**",

                            ">- 构建日志:    [点击查看详情](${env.BUILD_URL}console)",

                            // ">- 流水线:       [点击查看详情](${env.JOB_URL}console)",

                           // ">- 更新记录:    **${ChangeLog}**",

                             

                                   

                        ],

 

                        at: [

                          '所有人'

                        ]

            )

        }

    }

    

}

3.钉钉配置

系统配置下 id会自动生成对应pipeline下的post通知

 

image.png

通知如下

image.png

4.pipeline流水线Blue Ocean

 

地址:http://192.168.100.140:8080/blue/organizations/jenkins/pipelines

 

image.png

 

发布前端涉及checkout build 和deploy 目前没有更新回滚操作

 

5.流水线语法参考

作用pipeline 流水线拉取代码

image.png

 

生成jia包同步到服务器上

image.png

 
 
posted @ 2020-11-12 17:06  地铁昌平线  阅读(840)  评论(1编辑  收藏  举报