Jenkis pipeline构建菠菜源码搭建出售项目实践

在完成前文的jenkins server 在k8s环境部署 之后,本文我们来测试在k8s集群环境中的jenkins pipeline构建项目和更新,具体环境要求如下:
1、jenkins pipeline插件安装成功
2、要更新的应用已提前部署
3、Jenkins slave中需要有kubectl、svn、mvn客户端且环境变量设置准确
4、Jenkis
slave需要能和master的api-server进行正常通信(这里为了简便,前文构建jenkins
server的时候直接对defalut这个service
account做rabc授权。其他可选方案是使用~/.kube/config文件实现客户端的授权认证)
5、需要配置共享卷(slave编译完成之后把war包copy到共享卷位置)

一、创建构建菠菜源码搭建出售任务

有问题:http://haozbbs.com Q1157880099

1、点击“jenkins ”——“新建 ”——“pipeline”,输入项目的名称,点击“OK”

2、下拉到“pipeline”配置,填写脚本

具体脚本内容如下:

podTemplate(name: ‘jenkins-slave‘, cloud: ‘kubernetes‘,
  namespace: ‘default‘, label: ‘jenkins-slave‘,
  serviceAccount: ‘default‘, containers: [
  containerTemplate(
      name: ‘jenkins-slave‘,
      image: ‘harbor.59iedu.com/fjhb/jenkins-slave-toolkit:2018-08-10-v1‘,
      args: ‘${computer.jnlpmac} ${computer.name}‘,
      ttyEnabled: true,
      privileged: false,
      alwaysPullImage:true,
      )
  ],
  volumes: [
    persistentVolumeClaim(mountPath: ‘/tmp/‘, claimName: ‘tomcat-jcsj-data‘)
  ]) {
  node(‘jenkins-slave‘) {
    stage(‘svn-checkout‘) {
      container(‘jnlp‘) {
          sh """
          svn checkout --username=yanglw --password=mypassword http://192.168.1.81/svn/fjhbjsb/k8s-pipeline-test --non-interactive
          """
      }
    }

    stage(‘mvn-package‘) {
      container(‘jnlp‘) {
          sh """
          mkdir -p /var/jenkins_home && cd k8s-pipeline-test && mvn clean package && cp -rpf target/*.war /tmp/
          """
      }
    }

    stage(‘restart‘) {
      container(‘jnlp‘) {
          sh """
          pod_name=`kubectl  get pods -l name=jcsj-dev -o name | cut -d"/" -f2`
          kubectl delete pod \$pod_name
          """
      }
    }

    }
}

3、脚本释义
podTemplate节指定创建pod的模板和环境

Name:为pod的名称前缀
Cloud:为构建pod的云环境,需要和前面新建的云环境名称一样
Namespace:创建pod所在的namespace
Label: 创建pod对应的标签
serviceAccount:pod使用sa,这里使用default, 所以前文创建jenkins master deployment的时候多创建了一个default-role,这样自动创建出来的的jenkins-slave具有对应的api权限

containerTemplate节

指定创建容器的模板,当云环境里面配置pod模板后,容器模板以云环境的配置为准。

Volumes节

配置jenkins-slave pod挂载的卷,当云环境里面配置pod模板后,挂载卷以云环境配置为准

stage节为具体的pipeline步骤

这里第一步进行svn代码迁出;
第二步进行编译,并把包传到共享卷上面;
第三步对pod进行删除,因为应用采用deployment方式部署,所以可以实现重新创建pod,达到更新的效果。

二、构建准备

在开始构建之前,有必要介绍一下jcsj-dev的环境,这个环境是需要提前部署好的。部署文件如下

# cat deploy.yml
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: jcsj-dev
  namespace: default
spec:
  replicas: 1
  template:
    metadata:
      labels:
        name: jcsj-dev
    spec:
      containers:
      - name: jcsj-dev
        image: tomcat:latest
        imagePullPolicy: IfNotPresent
        ports:
        - name: web
          containerPort: 8080
        volumeMounts:
        - mountPath: /usr/local/tomcat/webapps
          name: tomcat-jcsj-data
      volumes:
      - name: tomcat-jcsj-data
        persistentVolumeClaim:
          claimName: tomcat-jcsj-data
---
apiVersion: v1
kind: Service
metadata:
  name: jcsj-dev
spec:
  type: NodePort
  ports:
    - port: 8080
      targetPort: 8080
      nodePort: 8453
  selector:
name: jcsj-dev
# cat pv.yaml
---
apiVersion: v1
kind: PersistentVolume
metadata:
  name: tomcat-jcsj-data
spec:
  capacity:
    storage: 5Gi
  accessModes:
  - ReadWriteMany
  nfs:
    path: /home/tomcat_jcsj
    server: 192.168.115.6
  persistentVolumeReclaimPolicy: Recycle 

---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: tomcat-jcsj-data
spec:
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 5Gi


三、更新项目代码

更新index.jsp并提交

四、开始构建

点击“立即构建”,构建过程中可以通过控制台输出看具体的日志信息


构建过程中观察jenkins master的日志输出:

# kubectl logs -f jenkins-master-588b89c75f-ztvgm
INFO: Started provisioning Kubernetes Pod Template from kubernetes with 1 executors. Remaining excess workload: 0
Aug 13, 2018 10:14:22 AM hudson.slaves.NodeProvisioner$2 run
INFO: Kubernetes Pod Template provisioning successfully completed. We have now 2 computer(s)
Aug 13, 2018 10:14:22 AM org.csanchez.jenkins.plugins.kubernetes.KubernetesLauncher launch
INFO: Created Pod: jenkins-slave-gjjbh in namespace default
Aug 13, 2018 10:14:22 AM org.csanchez.jenkins.plugins.kubernetes.KubernetesLauncher launch
INFO: Waiting for Pod to be scheduled (0/100): jenkins-slave-gjjbh
Aug 13, 2018 10:14:28 AM org.csanchez.jenkins.plugins.kubernetes.KubernetesLauncher launch
INFO: Container is waiting jenkins-slave-gjjbh [jnlp]: ContainerStateWaiting(message=null, reason=ContainerCreating, additionalProperties={})
Aug 13, 2018 10:14:28 AM org.csanchez.jenkins.plugins.kubernetes.KubernetesLauncher launch
INFO: Waiting for Pod to be scheduled (1/100): jenkins-slave-gjjbh
Aug 13, 2018 10:14:34 AM org.csanchez.jenkins.plugins.kubernetes.KubernetesLauncher launch
INFO: Waiting for agent to connect (1/100): jenkins-slave-gjjbh
Aug 13, 2018 10:14:35 AM org.csanchez.jenkins.plugins.kubernetes.KubernetesLauncher launch
INFO: Waiting for agent to connect (2/100): jenkins-slave-gjjbh
Aug 13, 2018 10:14:36 AM org.csanchez.jenkins.plugins.kubernetes.KubernetesLauncher launch
INFO: Waiting for agent to connect (3/100): jenkins-slave-gjjbh
Aug 13, 2018 10:14:37 AM org.csanchez.jenkins.plugins.kubernetes.KubernetesLauncher launch
INFO: Waiting for agent to connect (4/100): jenkins-slave-gjjbh
Aug 13, 2018 10:14:38 AM org.csanchez.jenkins.plugins.kubernetes.KubernetesLauncher launch
INFO: Waiting for agent to connect (5/100): jenkins-slave-gjjbh
Aug 13, 2018 10:14:39 AM org.csanchez.jenkins.plugins.kubernetes.KubernetesLauncher launch
INFO: Waiting for agent to connect (6/100): jenkins-slave-gjjbh
Aug 13, 2018 10:14:40 AM org.csanchez.jenkins.plugins.kubernetes.KubernetesLauncher launch
INFO: Waiting for agent to connect (7/100): jenkins-slave-gjjbh
Aug 13, 2018 10:14:41 AM org.csanchez.jenkins.plugins.kubernetes.KubernetesLauncher launch
INFO: Waiting for agent to connect (8/100): jenkins-slave-gjjbh
Aug 13, 2018 10:14:42 AM hudson.TcpSlaveAgentListener$ConnectionHandler run
INFO: Accepted JNLP4-connect connection #1 from /172.30.66.4:47408
Aug 13, 2018 10:14:42 AM org.csanchez.jenkins.plugins.kubernetes.KubernetesLauncher launch
INFO: Waiting for agent to connect (9/100): jenkins-slave-gjjbh
Aug 13, 2018 10:14:43 AM org.csanchez.jenkins.plugins.kubernetes.KubernetesLauncher launch
INFO: Waiting for agent to connect (10/100): jenkins-slave-gjjbh
Aug 13, 2018 10:14:44 AM org.csanchez.jenkins.plugins.kubernetes.KubernetesLauncher launch
INFO: Waiting for agent to connect (11/100): jenkins-slave-gjjbh
Aug 13, 2018 10:14:45 AM org.csanchez.jenkins.plugins.kubernetes.KubernetesLauncher launch
INFO: Waiting for agent to connect (12/100): jenkins-slave-gjjbh
Aug 13, 2018 10:14:46 AM org.csanchez.jenkins.plugins.kubernetes.KubernetesLauncher launch
INFO: Waiting for agent to connect (13/100): jenkins-slave-gjjbh
Aug 13, 2018 10:14:47 AM org.csanchez.jenkins.plugins.kubernetes.KubernetesLauncher launch
INFO: Waiting for agent to connect (14/100): jenkins-slave-gjjbh
Aug 13, 2018 10:14:48 AM org.csanchez.jenkins.plugins.kubernetes.KubernetesLauncher launch
INFO: Waiting for agent to connect (15/100): jenkins-slave-gjjbh
Aug 13, 2018 10:14:49 AM org.csanchez.jenkins.plugins.kubernetes.KubernetesLauncher launch
INFO: Waiting for agent to connect (16/100): jenkins-slave-gjjbh
Aug 13, 2018 10:14:50 AM org.csanchez.jenkins.plugins.kubernetes.KubernetesLauncher launch
INFO: Waiting for agent to connect (17/100): jenkins-slave-gjjbh
Aug 13, 2018 10:14:51 AM org.csanchez.jenkins.plugins.kubernetes.KubernetesLauncher launch
INFO: Waiting for agent to connect (18/100): jenkins-slave-gjjbh
Aug 13, 2018 10:14:52 AM org.csanchez.jenkins.plugins.kubernetes.KubernetesLauncher launch
INFO: Waiting for agent to connect (19/100): jenkins-slave-gjjbh
Aug 13, 2018 10:14:53 AM org.csanchez.jenkins.plugins.kubernetes.KubernetesLauncher launch
INFO: Waiting for agent to connect (20/100): jenkins-slave-gjjbh
Aug 13, 2018 10:15:12 AM org.csanchez.jenkins.plugins.kubernetes.pipeline.ContainerExecDecorator$1 doLaunch
INFO: Created process inside pod: [jenkins-slave-gjjbh], container: [jnlp] with pid:[-1]
Aug 13, 2018 10:15:21 AM org.csanchez.jenkins.plugins.kubernetes.pipeline.ContainerExecDecorator$1 doLaunch
INFO: Created process inside pod: [jenkins-slave-gjjbh], container: [jnlp] with pid:[-1]
Aug 13, 2018 10:16:04 AM org.csanchez.jenkins.plugins.kubernetes.pipeline.ContainerExecDecorator$1 doLaunch
INFO: Created process inside pod: [jenkins-slave-gjjbh], container: [jnlp] with pid:[-1]
Aug 13, 2018 10:16:06 AM org.csanchez.jenkins.plugins.kubernetes.KubernetesSlave _terminate
INFO: Terminating Kubernetes instance for agent jenkins-slave-gjjbh
Aug 13, 2018 10:16:06 AM jenkins.slaves.DefaultJnlpSlaveReceiver channelClosed
WARNING: Computer.threadPoolForRemoting [#8] for jenkins-slave-gjjbh terminated
java.nio.channels.ClosedChannelException
        at org.jenkinsci.remoting.protocol.impl.ChannelApplicationLayer.onReadClosed(ChannelApplicationLayer.java:208)
        at org.jenkinsci.remoting.protocol.ApplicationLayer.onRecvClosed(ApplicationLayer.java:222)
        at org.jenkinsci.remoting.protocol.ProtocolStack$Ptr.onRecvClosed(ProtocolStack.java:832)
        at org.jenkinsci.remoting.protocol.FilterLayer.onRecvClosed(FilterLayer.java:287)
        at org.jenkinsci.remoting.protocol.impl.SSLEngineFilterLayer.onRecvClosed(SSLEngineFilterLayer.java:181)
        at org.jenkinsci.remoting.protocol.impl.SSLEngineFilterLayer.switchToNoSecure(SSLEngineFilterLayer.java:283)
        at org.jenkinsci.remoting.protocol.impl.SSLEngineFilterLayer.processWrite(SSLEngineFilterLayer.java:503)
        at org.jenkinsci.remoting.protocol.impl.SSLEngineFilterLayer.processQueuedWrites(SSLEngineFilterLayer.java:248)
        at org.jenkinsci.remoting.protocol.impl.SSLEngineFilterLayer.doSend(SSLEngineFilterLayer.java:200)
        at org.jenkinsci.remoting.protocol.impl.SSLEngineFilterLayer.doCloseSend(SSLEngineFilterLayer.java:213)
        at org.jenkinsci.remoting.protocol.ProtocolStack$Ptr.doCloseSend(ProtocolStack.java:800)
        at org.jenkinsci.remoting.protocol.ApplicationLayer.doCloseWrite(ApplicationLayer.java:173)
        at org.jenkinsci.remoting.protocol.impl.ChannelApplicationLayer$ByteBufferCommandTransport.closeWrite(ChannelApplicationLayer.java:311)
        at hudson.remoting.Channel.close(Channel.java:1295)
        at hudson.remoting.Channel.close(Channel.java:1263)
        at hudson.slaves.SlaveComputer.closeChannel(SlaveComputer.java:708)
        at hudson.slaves.SlaveComputer.access$800(SlaveComputer.java:96)
        at hudson.slaves.SlaveComputer$3.run(SlaveComputer.java:626)
        at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)

Aug 13, 2018 10:16:06 AM org.csanchez.jenkins.plugins.kubernetes.pipeline.PodTemplateStepExecution$PodTemplateCallback finished
INFO: Removing pod template and deleting pod jenkins-slave-7gnwx from cloud kubernetes
Aug 13, 2018 10:16:06 AM org.csanchez.jenkins.plugins.kubernetes.KubernetesSlave _terminate
INFO: Terminated Kubernetes instance for agent default/jenkins-slave-gjjbh
Aug 13, 2018 10:16:06 AM org.csanchez.jenkins.plugins.kubernetes.KubernetesSlave _terminate
INFO: Disconnected computer jenkins-slave-gjjbh
Terminated Kubernetes instance for agent default/jenkins-slave-gjjbh
Aug 13, 2018 10:16:06 AM org.csanchez.jenkins.plugins.kubernetes.pipeline.PodTemplateStepExecution$PodTemplateCallback finished
WARNING: Failed to delete pod for agent default/jenkins-slave-7gnwx: not found
Aug 13, 2018 10:16:07 AM org.jenkinsci.plugins.workflow.job.WorkflowRun finish
INFO: k8s-pipeline-test #1 completed: SUCCESS

五、验证结果

六、后记

本文仅介绍的pipeline方式构建项目的过程,实际应用中还需要解决若干问题,例如: http://niusilingyuanmaxiazai.ahfv.top/

1、svn checkout步骤需要明文配置用户名和密码,存在安全性问题
2、 每次执行构建都需要全量迁出代码,效率不高
3、要更新的应用需要提前部署好,不能适配首次编译部署场景
4、对共享卷存在依赖,解耦问题需要解决

后续将介绍maven项目的构建和自动部署!

原文地址:https://www.cnblogs.com/chunchunde/p/9485959.html

时间: 2024-11-05 17:24:55

Jenkis pipeline构建菠菜源码搭建出售项目实践的相关文章

了解html5特性 H5二八杠牌九源码搭建出售教程

HTML5开发技术是互联网行业当中的一次伟大的改革,它的到来,预示着一个新时代的到来,各种以HTML5为基础的应用纷纷闪亮登场,微信小程序的狂潮就是在这种情况下产生的.同时,HTML5的出现,H5二八杠牌九源码搭建出售Q-2189563389也为Web前端开发技术增添了一道亮丽的光彩.在HTML5到来之前,前端开发人员想要实现同样的功效,就必须要不断的重复编写代码,调试,更新,耗费较多的时间.而随着HTML5时代的到来,这一切都变得十分简单. 什么是HTML5? HTML是万维网的核心语言,即超

JAVA数据杏彩源码搭建出售结构之链表

链表应该是继数组之后应用最广的通用存储结构,链表的机制灵活,用途广泛,适用于许多通用的数据库,也可取代数组作为其他的存储结构的基础,如栈和队列,除非需要频繁地通过下标访问数据,否则在很多使用数组的地方都可以使用链表来代替. 接下来本篇博文会讲解到单链表,双端链表,有序链表,双向链表,和有迭代器的链表.(迭代器是用来随机访问链表元素的一种方法) 链表的实现一般需要用到两个类,链表对象(包含对第一个链表节点的引用),链表节点(所有保存的数据,和对下一个链表节点的引用).这种 方式可以称作自引式,由于

Java加密杏彩源码搭建出售加签算法到php的坑

写代码的经历中,总少不了与外部的程序对接,一旦有这样的事,往往周期会很长,很麻烦,因为你要考虑的事会多了很多,其中安全性的加密解密就是重要的一项.写代码,可以出Bug,但逼格不能弱.什么是逼格?和别人对接一下,连加密解密都没有,连验证签名都没有,别人一眼就望穿你,这就是眼界的问题了. 这次的故事是对接一个大的支付系统,对方也是第一个对接我们,然后定了接口和加解密算法,给了个Java的Demo,问了声,有没有PHP的,没有,歇菜,自己来吧. 代码说多不多,说少不少,为了先说事,代码放在最后面. 第

菠菜源码搭建与微信小程序Demo

demo 的界面设计以及交互设计 工具 菠菜源码搭建QQ:2152876294 网址diguaym.com已经全面对非邀请内测用户开放, 且在持续更新(我码代码的过程中就更新了两版, 所以开发时 IDE 版本不唯一) 不过其实忍受了半个小时微信的开发者工具之后, 我就改在 webstorm 中编辑了, 微信工具成了运行预览的工具, 不过听说IDE 中预览的效果, 也不能保证与真机一样哦~ 设计和功能: 知乎安卓版本 非常之简易版数据: 毕竟是知乎, 为了防止版权问题, fake 的数据使用的是我

菠菜源码搭建与java基础概念

1.java jvm的功能:通过 ClassLoader 寻找和装载 class 文件?? ??? ??? ?? 解释字节码成为指令并执行,提供 class 文件的运行环境?? ??? ??? ?? 进行运行期间垃圾回收 菠菜源码搭建QQ:2152876294 网址diguaym.com?? ??? ??? ?? 提供与硬件交互的平台?? ?2.运算符优先级:单目 >运算>移位>比较>按位>逻辑>三目 >赋值?? ??? ??? ?单目:单目运算符+ –(负数)

android适配华为菠菜源码搭建虚拟键

在做菠菜源码搭建 dsluntan.com VX:17061863513横竖屏展示时,发现网上适配虚拟键代码没有做横屏状态下适配,导致横屏状态下,底部虚拟键遮挡了布局内容. 所以横屏状态下也需要适配华为虚拟键.只需要在content布局改变时,同时记录当前可用的视图宽度,重新请求布局即可.下面是代码: import android.content.Context;import android.content.res.Resources;import android.graphics.Rect;i

redhat multipath中幸运飞艇源码搭建出售配置文件简要说明

redhat multipath多路径文件大致分为是两个部分,幸运飞艇源码搭建出售Q[1152880099]multipath和device部分. 使用 mpathconf 程序设置多路径,它可创建多路径配置文件 /etc/multipath.conf.如果 /etc/multipath.conf 文件已存在,mpathconf 程序将会编辑该文件.如果 /etc/multipath.conf 文件不存在,mpathconf 程序将使用 /usr/share/doc/device-mapper-

MySQL 8 新特性之信用盘源码搭建出售降序索引实现

什么是降序索引 大家可能对索引比较熟悉,而对降序索引比较陌生,事实上降序索引是索引的子集. 我们通常使用下面的语句来创建一个索引: 信用盘源码搭建出售q-1152880099 create index idx_t1_bcd on t1(b,c,d); 上面sql的意思是在t1表中,针对b,c,d三个字段创建一个联合索引. 但是大家不知道的是,上面这个sql实际上和下面的这个sql是等价的: create index idx_t1_bcd on t1(b asc,c asc,d asc); asc

彩38源码搭建与项目中遇到的bug

1.Redis服务器 can not get resource from pool.1000个线程并发还能跑,5000个线程的时候出现这种问题,彩38源码搭建QQ:2152876294 网址diguaym.com后台debug日志,发现redis 线程池不够.刚开始设置的是: redis 配置文件 #redisredis.host=127.0.0.1redis.port=6379redis.timeout=300 等待时间 10s改为300sredis.password=123456redis.