4. 添加参数
# 参数 1. name: git_repo type: string description: 项目在git版本仓库的地址,如 https://gitee.com/xxx/dubbo-demo-service.git 2. name: app_name type: string description: 项目名称,如 dubbo-demo-service 3. name: git_ver type: string description: 项目在git仓库中对应的分支或者版本号 4. name: maven type: choice description: 编译时使用的maven目录中的版本号部分 5. name: mvn_cmd type: string default: mvn clean package -Dmaven.test.skip=true description: 执行编译所用的指令 6. name: mvn_dir type: string default: ./ description: 在哪个目录执行编译,由开发同事提供 7. name: target_dir type: string default: ./target description: 编译的jar/war文件存放目录,由开发同事提供 8. name: base_image type: choice default: description: 项目使用的jre底包 9. name: image_name type: string description: docker镜像名称,如 app/dubbo-demo-service 10. name: add_tag type: string default: description: 日期-时间,和git_ver拼在一起组成镜像的tag,如: 202002011001
5.设置流水线构建脚本
pipeline { agent any stages { stage(‘pull‘) { //get project code from repo steps { sh "git clone ${params.git_repo} ${params.app_name}/${env.BUILD_NUMBER} && cd ${params.app_name}/${env.BUILD_NUMBER} && git checkout ${params.git_ver}" } } stage(‘build‘) { //exec mvn cmd steps { sh "cd ${params.app_name}/${env.BUILD_NUMBER} && /var/jenkins_home/maven-${params.maven}/bin/${params.mvn_cmd}" } } stage(‘package‘) { //move jar file into project_dir steps { sh "cd ${params.app_name}/${env.BUILD_NUMBER} && cd ${params.target_dir} && mkdir project_dir && mv *.jar ./project_dir" } } stage(‘image‘) { //build image and push to registry steps { writeFile file: "${params.app_name}/${env.BUILD_NUMBER}/Dockerfile", text: """FROM harbor.fx.com/${params.base_image} ADD ${params.target_dir}/project_dir /opt/project_dir""" sh "cd ${params.app_name}/${env.BUILD_NUMBER} && docker build -t harbor.fx.com/${params.image_name}:${params.git_ver}_${params.add_tag} . && docker push harbor.fx.com/${params.image_name}:${params.git_ver}_${params.add_tag}" } } } }
6.保存配置
7.私有仓库创建一个名称为app的项目,属性为私有
8.执行流水线
9.输入相关参数
10.构建成功
12. 准备dubbo-demo-service的k8s资源配置清单文件
[root@hdss7-200 dubbo-demo-service]# vim deployment.yaml kind: Deployment apiVersion: extensions/v1beta1 metadata: name: dubbo-demo-service namespace: app labels: name: dubbo-demo-service spec: replicas: 1 selector: matchLabels: name: dubbo-demo-service template: metadata: labels: app: dubbo-demo-service name: dubbo-demo-service spec: containers: - name: dubbo-demo-service image: harbor.fx.com/app/dubbo-demo-service:master_20200617_1849 ports: - containerPort: 20880 protocol: TCP env: - name: JAR_BALL value: dubbo-server.jar imagePullPolicy: IfNotPresent imagePullSecrets: - name: harbor restartPolicy: Always terminationGracePeriodSeconds: 30 securityContext: runAsUser: 0 schedulerName: default-scheduler strategy: type: RollingUpdate rollingUpdate: maxUnavailable: 1 maxSurge: 1 revisionHistoryLimit: 7 progressDeadlineSeconds: 600
13.查看zookeeper的状态
[root@hdss7-11 bin]# ./zkServer.sh status ZooKeeper JMX enabled by default Using config: /opt/zookeeper/bin/../conf/zoo.cfg Client port found: 2181. Client address: localhost. Mode: follower
[root@hdss7-11 bin]# ./zkCli.sh -server localhost:2181 [zk: localhost:2181(CONNECTED) 0] ls / [zookeeper] [zk: localhost:2181(CONNECTED) 1]
14.应用dubbo-demo-service的k8s的资源配置清单
[root@hdss7-21 ~]# kubectl create namespace app [root@hdss7-21 ~]# kubectl create secret docker-registry harbor --docker-server=harbor.fx.com --docker-username=admin --docker-password=Harbor12345 -n app [root@hdss7-21 ~]# kubectl apply -f http://k8s-yaml.fx.com/dubbo-demo-service/deployment.yaml
15.再次查看zookeeper
[zk: localhost:2181(CONNECTED) 0] ls / [dubbo, zookeeper] [zk: localhost:2181(CONNECTED) 1]
11.实战交付一套dubbo微服务到k8s集群(4)之使用Jenkins进行持续构建交付dubo服务的提供者
原文:https://www.cnblogs.com/fxxy/p/13158925.html