首页 > 其他分享 >k8s jenkines kubesphere 部署流水线样例

k8s jenkines kubesphere 部署流水线样例

时间:2023-08-11 14:13:05浏览次数:43  
标签:jenkines service kubesphere 样例 sh VAR docker DOCKER stage

pipeline {
    agent {
        node {
            label 'maven'
        }

    }
    stages {
        stage('拉取代码') {
            agent none
            steps {
                container('maven') {
                    git(url: 'https://gitee.com/leifengyang/yygh-parent.git', credentialsId: 'gitee-id', branch: 'master', changelog: true, poll: false)
                    sh 'ls -al'
                }

            }
        }

        stage('项目编译') {
            agent none
            steps {
                container('maven') {
                    sh 'ls'
                    sh 'mvn clean package -Dmaven.test.skip=true'
                    sh 'ls hospital-manage/target'
                }

            }
        }

        stage('default-2') {
            parallel {
                stage('构建hospital-manage镜像') {
                    agent none
                    steps {
                        container('maven') {
                            sh 'ls hospital-manage/target'
                            sh 'docker build -t hospital-manage:latest -f hospital-manage/Dockerfile  ./hospital-manage/'
                        }

                    }
                }

                stage('构建server-gateway镜像') {
                    agent none
                    steps {
                        container('maven') {
                            sh 'ls server-gateway/target'
                            sh 'docker build -t server-gateway:latest -f server-gateway/Dockerfile  ./server-gateway/'
                        }

                    }
                }

                stage('构建service-cmn镜像') {
                    agent none
                    steps {
                        container('maven') {
                            sh 'ls service/service-cmn/target'
                            sh 'docker build -t service-cmn:latest -f service/service-cmn/Dockerfile  ./service/service-cmn/'
                        }

                    }
                }

                stage('构建service-hosp镜像') {
                    agent none
                    steps {
                        container('maven') {
                            sh 'ls service/service-hosp/target'
                            sh 'docker build -t service-hosp:latest -f service/service-hosp/Dockerfile  ./service/service-hosp/'
                        }

                    }
                }

                stage('构建service-order镜像') {
                    agent none
                    steps {
                        container('maven') {
                            sh 'ls service/service-order/target'
                            sh 'docker build -t service-order:latest -f service/service-order/Dockerfile  ./service/service-order/'
                        }

                    }
                }

                stage('构建service-oss镜像') {
                    agent none
                    steps {
                        container('maven') {
                            sh 'ls service/service-oss/target'
                            sh 'docker build -t service-oss:latest -f service/service-oss/Dockerfile  ./service/service-oss/'
                        }

                    }
                }

                stage('构建service-sms镜像') {
                    agent none
                    steps {
                        container('maven') {
                            sh 'ls service/service-sms/target'
                            sh 'docker build -t service-sms:latest -f service/service-sms/Dockerfile  ./service/service-sms/'
                        }

                    }
                }

                stage('构建service-statistics镜像') {
                    agent none
                    steps {
                        container('maven') {
                            sh 'ls service/service-statistics/target'
                            sh 'docker build -t service-statistics:latest -f service/service-statistics/Dockerfile  ./service/service-statistics/'
                        }

                    }
                }

                stage('构建service-task镜像') {
                    agent none
                    steps {
                        container('maven') {
                            sh 'ls service/service-task/target'
                            sh 'docker build -t service-task:latest -f service/service-task/Dockerfile  ./service/service-task/'
                        }

                    }
                }

                stage('构建service-user镜像') {
                    agent none
                    steps {
                        container('maven') {
                            sh 'ls service/service-user/target'
                            sh 'docker build -t service-user:latest -f service/service-user/Dockerfile  ./service/service-user/'
                        }

                    }
                }

            }
        }

        stage('default-3') {
            parallel {
                stage('推送hospital-manage镜像') {
                    agent none
                    steps {
                        container('maven') {
                            withCredentials([usernamePassword(credentialsId : 'aliyun-docker-registry' ,usernameVariable : 'DOCKER_USER_VAR' ,passwordVariable : 'DOCKER_PWD_VAR' ,)]) {
                                sh 'echo "$DOCKER_PWD_VAR" | docker login $REGISTRY -u "$DOCKER_USER_VAR" --password-stdin'
                                sh 'docker tag hospital-manage:latest $REGISTRY/$DOCKERHUB_NAMESPACE/hospital-manage:SNAPSHOT-$BUILD_NUMBER'
                                sh 'docker push  $REGISTRY/$DOCKERHUB_NAMESPACE/hospital-manage:SNAPSHOT-$BUILD_NUMBER'
                            }

                        }

                    }
                }

                stage('推送server-gateway镜像') {
                    agent none
                    steps {
                        container('maven') {
                            withCredentials([usernamePassword(credentialsId : 'aliyun-docker-registry' ,usernameVariable : 'DOCKER_USER_VAR' ,passwordVariable : 'DOCKER_PWD_VAR' ,)]) {
                                sh 'echo "$DOCKER_PWD_VAR" | docker login $REGISTRY -u "$DOCKER_USER_VAR" --password-stdin'
                                sh 'docker tag server-gateway:latest $REGISTRY/$DOCKERHUB_NAMESPACE/server-gateway:SNAPSHOT-$BUILD_NUMBER'
                                sh 'docker push  $REGISTRY/$DOCKERHUB_NAMESPACE/server-gateway:SNAPSHOT-$BUILD_NUMBER'
                            }

                        }

                    }
                }

                stage('推送service-cmn镜像') {
                    agent none
                    steps {
                        container('maven') {
                            withCredentials([usernamePassword(credentialsId : 'aliyun-docker-registry' ,usernameVariable : 'DOCKER_USER_VAR' ,passwordVariable : 'DOCKER_PWD_VAR' ,)]) {
                                sh 'echo "$DOCKER_PWD_VAR" | docker login $REGISTRY -u "$DOCKER_USER_VAR" --password-stdin'
                                sh 'docker tag service-cmn:latest $REGISTRY/$DOCKERHUB_NAMESPACE/service-cmn:SNAPSHOT-$BUILD_NUMBER'
                                sh 'docker push  $REGISTRY/$DOCKERHUB_NAMESPACE/service-cmn:SNAPSHOT-$BUILD_NUMBER'
                            }

                        }

                    }
                }

                stage('推送service-hosp镜像') {
                    agent none
                    steps {
                        container('maven') {
                            withCredentials([usernamePassword(credentialsId : 'aliyun-docker-registry' ,usernameVariable : 'DOCKER_USER_VAR' ,passwordVariable : 'DOCKER_PWD_VAR' ,)]) {
                                sh 'echo "$DOCKER_PWD_VAR" | docker login $REGISTRY -u "$DOCKER_USER_VAR" --password-stdin'
                                sh 'docker tag service-hosp:latest $REGISTRY/$DOCKERHUB_NAMESPACE/service-hosp:SNAPSHOT-$BUILD_NUMBER'
                                sh 'docker push  $REGISTRY/$DOCKERHUB_NAMESPACE/service-hosp:SNAPSHOT-$BUILD_NUMBER'
                            }

                        }

                    }
                }

                stage('推送service-order镜像') {
                    agent none
                    steps {
                        container('maven') {
                            withCredentials([usernamePassword(credentialsId : 'aliyun-docker-registry' ,usernameVariable : 'DOCKER_USER_VAR' ,passwordVariable : 'DOCKER_PWD_VAR' ,)]) {
                                sh 'echo "$DOCKER_PWD_VAR" | docker login $REGISTRY -u "$DOCKER_USER_VAR" --password-stdin'
                                sh 'docker tag service-order:latest $REGISTRY/$DOCKERHUB_NAMESPACE/service-order:SNAPSHOT-$BUILD_NUMBER'
                                sh 'docker push  $REGISTRY/$DOCKERHUB_NAMESPACE/service-order:SNAPSHOT-$BUILD_NUMBER'
                            }

                        }

                    }
                }

                stage('推送service-oss镜像') {
                    agent none
                    steps {
                        container('maven') {
                            withCredentials([usernamePassword(credentialsId : 'aliyun-docker-registry' ,usernameVariable : 'DOCKER_USER_VAR' ,passwordVariable : 'DOCKER_PWD_VAR' ,)]) {
                                sh 'echo "$DOCKER_PWD_VAR" | docker login $REGISTRY -u "$DOCKER_USER_VAR" --password-stdin'
                                sh 'docker tag service-oss:latest $REGISTRY/$DOCKERHUB_NAMESPACE/service-oss:SNAPSHOT-$BUILD_NUMBER'
                                sh 'docker push  $REGISTRY/$DOCKERHUB_NAMESPACE/service-oss:SNAPSHOT-$BUILD_NUMBER'
                            }

                        }

                    }
                }

                stage('推送service-sms镜像') {
                    agent none
                    steps {
                        container('maven') {
                            withCredentials([usernamePassword(credentialsId : 'aliyun-docker-registry' ,usernameVariable : 'DOCKER_USER_VAR' ,passwordVariable : 'DOCKER_PWD_VAR' ,)]) {
                                sh 'echo "$DOCKER_PWD_VAR" | docker login $REGISTRY -u "$DOCKER_USER_VAR" --password-stdin'
                                sh 'docker tag service-sms:latest $REGISTRY/$DOCKERHUB_NAMESPACE/service-sms:SNAPSHOT-$BUILD_NUMBER'
                                sh 'docker push  $REGISTRY/$DOCKERHUB_NAMESPACE/service-sms:SNAPSHOT-$BUILD_NUMBER'
                            }

                        }

                    }
                }

                stage('推送service-statistics镜像') {
                    agent none
                    steps {
                        container('maven') {
                            withCredentials([usernamePassword(credentialsId : 'aliyun-docker-registry' ,usernameVariable : 'DOCKER_USER_VAR' ,passwordVariable : 'DOCKER_PWD_VAR' ,)]) {
                                sh 'echo "$DOCKER_PWD_VAR" | docker login $REGISTRY -u "$DOCKER_USER_VAR" --password-stdin'
                                sh 'docker tag service-statistics:latest $REGISTRY/$DOCKERHUB_NAMESPACE/service-statistics:SNAPSHOT-$BUILD_NUMBER'
                                sh 'docker push  $REGISTRY/$DOCKERHUB_NAMESPACE/service-statistics:SNAPSHOT-$BUILD_NUMBER'
                            }

                        }

                    }
                }

                stage('推送service-task镜像') {
                    agent none
                    steps {
                        container('maven') {
                            withCredentials([usernamePassword(credentialsId : 'aliyun-docker-registry' ,usernameVariable : 'DOCKER_USER_VAR' ,passwordVariable : 'DOCKER_PWD_VAR' ,)]) {
                                sh 'echo "$DOCKER_PWD_VAR" | docker login $REGISTRY -u "$DOCKER_USER_VAR" --password-stdin'
                                sh 'docker tag service-task:latest $REGISTRY/$DOCKERHUB_NAMESPACE/service-task:SNAPSHOT-$BUILD_NUMBER'
                                sh 'docker push  $REGISTRY/$DOCKERHUB_NAMESPACE/service-task:SNAPSHOT-$BUILD_NUMBER'
                            }

                        }

                    }
                }

                stage('推送service-user镜像') {
                    agent none
                    steps {
                        container('maven') {
                            withCredentials([usernamePassword(credentialsId : 'aliyun-docker-registry' ,usernameVariable : 'DOCKER_USER_VAR' ,passwordVariable : 'DOCKER_PWD_VAR' ,)]) {
                                sh 'echo "$DOCKER_PWD_VAR" | docker login $REGISTRY -u "$DOCKER_USER_VAR" --password-stdin'
                                sh 'docker tag service-user:latest $REGISTRY/$DOCKERHUB_NAMESPACE/service-user:SNAPSHOT-$BUILD_NUMBER'
                                sh 'docker push  $REGISTRY/$DOCKERHUB_NAMESPACE/service-user:SNAPSHOT-$BUILD_NUMBER'
                            }

                        }

                    }
                }

            }
        }

        stage('default-4') {
            parallel {
                stage('hospital-manage - 部署到dev环境') {
                    agent none
                    steps {
                        kubernetesDeploy(configs: 'hospital-manage/deploy/**', enableConfigSubstitution: true, kubeconfigId: "$KUBECONFIG_CREDENTIAL_ID")
                    }
                }

                stage('server-gateway - 部署到dev环境') {
                    agent none
                    steps {
                        kubernetesDeploy(configs: 'server-gateway/deploy/**', enableConfigSubstitution: true, kubeconfigId: "$KUBECONFIG_CREDENTIAL_ID")
                    }
                }

                stage('service-cmn - 部署到dev环境') {
                    agent none
                    steps {
                        kubernetesDeploy(configs: 'service/service-cmn/deploy/**', enableConfigSubstitution: true, kubeconfigId: "$KUBECONFIG_CREDENTIAL_ID")
                    }
                }

                stage('service-hosp - 部署到dev环境') {
                    agent none
                    steps {
                        kubernetesDeploy(configs: 'service/service-hosp/deploy/**', enableConfigSubstitution: true, kubeconfigId: "$KUBECONFIG_CREDENTIAL_ID")
                    }
                }

                stage('service-order - 部署到dev环境') {
                    agent none
                    steps {
                        kubernetesDeploy(configs: 'service/service-order/deploy/**', enableConfigSubstitution: true, kubeconfigId: "$KUBECONFIG_CREDENTIAL_ID")
                    }
                }

                stage('service-oss - 部署到dev环境') {
                    agent none
                    steps {
                        kubernetesDeploy(configs: 'service/service-oss/deploy/**', enableConfigSubstitution: true, kubeconfigId: "$KUBECONFIG_CREDENTIAL_ID")
                    }
                }

                stage('service-sms - 部署到dev环境') {
                    agent none
                    steps {
                        kubernetesDeploy(configs: 'service/service-sms/deploy/**', enableConfigSubstitution: true, kubeconfigId: "$KUBECONFIG_CREDENTIAL_ID")
                    }
                }

                stage('service-statistics - 部署到dev环境') {
                    agent none
                    steps {
                        kubernetesDeploy(configs: 'service/service-statistics/deploy/**', enableConfigSubstitution: true, kubeconfigId: "$KUBECONFIG_CREDENTIAL_ID")
                    }
                }

                stage('service-task - 部署到dev环境') {
                    agent none
                    steps {
                        kubernetesDeploy(configs: 'service/service-task/deploy/**', enableConfigSubstitution: true, kubeconfigId: "$KUBECONFIG_CREDENTIAL_ID")
                    }
                }

                stage('service-user - 部署到dev环境') {
                    agent none
                    steps {
                        kubernetesDeploy(configs: 'service/service-user/deploy/**', enableConfigSubstitution: true, kubeconfigId: "$KUBECONFIG_CREDENTIAL_ID")
                    }
                }

            }
        }

        //1、配置全系统的邮件:                   全系统的监控
        //2、修改ks-jenkins的配置,里面的邮件;   流水线发邮件
        stage('发送确认邮件') {
            agent none
            steps {
                mail(to: '[email protected]', subject: '构建结果', body: "构建成功了  $BUILD_NUMBER")
            }
        }

    }
    environment {
        DOCKER_CREDENTIAL_ID = 'dockerhub-id'
        GITHUB_CREDENTIAL_ID = 'github-id'
        KUBECONFIG_CREDENTIAL_ID = 'demo-kubeconfig'
        REGISTRY = 'registry.cn-hangzhou.aliyuncs.com'
        DOCKERHUB_NAMESPACE = 'lfy_hello'
        GITHUB_ACCOUNT = 'kubesphere'
        APP_NAME = 'devops-java-sample'
        ALIYUNHUB_NAMESPACE = 'lfy_hello'
    }
    parameters {
        string(name: 'TAG_NAME', defaultValue: '', description: '')
    }
}

 

标签:jenkines,service,kubesphere,样例,sh,VAR,docker,DOCKER,stage
From: https://www.cnblogs.com/niun/p/17622819.html

相关文章

  • KubeSphere 部署 Zookeeper 实战教程
    前言知识点定级:入门级如何利用AI助手辅助运维工作单节点Zookeeper安装部署集群模式Zookeeper安装部署开源应用选型思想实战服务器配置(架构1:1复刻小规模生产环境,配置略有不同)主机名IPCPU内存系统盘数据盘用途ks-master-0192.168.9.9148501......
  • 皮肤控件IrisSkin4.dll调用样例
    最近做一些C#数据库开发项目,基本窗体程序做好之后,发现界面较为丑陋,然而,自己又不善于美工,所以想到了求助于第三方帮忙。网上有较多的是利用IrisSkin2.dll文件来开发,然后,本人按照一些解决方案做下来,发现该链接库并不会适合VS2010平台开发的Winform,故此,寻找替代方案,然后,发现了IrisSki......
  • SpringSecurity1: spring boot web 样例快速体验
    本文只讲操作实践,不讲原理,这样对于想快速搭建起一个基于SpringSecurity的Web项目的朋友们而言,比较友好。文章主要由两部分构成:快速演示样例所有账户和授权数据均基于内存,能在极短的时间内搭建和运行起来,可以快速体验SpringSecurity简易生产样例建议想参考原型,在自己工程中......
  • KubeSphere 社区双周报 | 本周六上海站 Meetup 准时开启 | 2023.7.21-08.03
    KubeSphere社区双周报主要整理展示新增的贡献者名单和证书、新增的讲师证书以及两周内提交过commit的贡献者,并对近期重要的PR进行解析,同时还包含了线上/线下活动和布道推广等一系列社区动态。本次双周报涵盖时间为:2023.07.21-2023.08.04。贡献者名单新晋KubeSphereCon......
  • KubeSphere 3.4.0 发布:支持 K8s v1.26
    2023年07月26日,KubeSphere开源社区激动地向大家宣布,KubeSphere3.4.0正式发布!让我们先简单回顾下之前三个大版本的主要变化:KubeSphere3.1.0新增了“边缘计算”、“计量计费”等功能,将Kubernetes从云端扩展至边缘;KubeSphere3.2.0新增了对“GPU资源调度管理”......
  • Locust 压测socket接口样例
    importsocketfromlocustimportUser,task,between,constantclassSocketUser(User):#初始化,建立Socket连接defon_start(self):self.client=socket.socket(socket.AF_INET,socket.SOCK_STREAM)self.client.connect(('localhost',8080))#替换为目标Socket服务......
  • 某制造企业基于 KubeSphere 的云原生实践
    背景介绍随着业务升级改造与软件产品专案的增多,常规的物理机和虚拟机方式逐渐暴露出一些问题:大量服务部署在虚拟机上,资源预估和硬件浪费较大;大量服务部署在虚拟机上,部署时间和难度较大,自动化程度较低;开发人员和运维人员,由于开发和部署服务环境不同,服务不稳定经常报错,产生的隔阂问题......
  • 东方通信基于 KubeSphere 的云计算落地经验
    作者:周峰吴昌泰公司简介东方通信股份有限公司(以下简称“东方通信”)创立于1958年,是一家集硬件设备、软件、服务为一体的整体解决方案提供商。公司于1996年成功改制上市,成为上海证交所同时发行A股和B股的国有控股上市公司。公司业务主要包括:专网通信及信息安全产品和解决......
  • 【HarmonyOS】元服务隐私协议开发指导样例
    【关键字】隐私、弹窗、元服务、协议 【介绍】每个元服务必须提供隐私声明,否则将导致提交元服务发布上架时,审核无法通过。隐私声明的具体要求请参见隐私声明规范。用户使用元服务前,必须引导其了解隐私声明信息,获取用户授权后,才能继续使用元服务。废话不多说,上代码!! 【方式......
  • kubesphere 重新部署deployment的页面实现
    找到工作负载的某一个,点击:部署那边点击重新创建即可 ......