码迷,mamicode.com
首页 > 其他好文 > 详细

jenkins自动化pipline的ci/cd流水线

时间:2019-08-07 18:47:37      阅读:102      评论:0      收藏:0      [点我收藏+]

标签:pull   tab   rop   ima   agent   one   port   lag   pipe   

pipeline {
    agent any
   tools {
        //工具必须预先在jenkins中预配置
        maven mvn
        jdk  jdk
    }
    stages {
        stage(Env) {
           
            steps {
                sh printenv
            }
        }
        stage(git)     {
         steps{
           checkout([$class: GitSCM, branches: [[name: */develop]], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 18980d0a-1ae4-443b17dc687b1, url: https://CFAI_the_best/codeflag-basis.git]]])
         }
   }
        stage(mvn install)     { 
          
           steps {
            
              sh cd /var/lib/jenkins/workspace/k8s-test-basis/src/main/resources && mv application.test.properties application.properties
              
              sh mvn clean install
              
           }
          
       }
        stage(docker)     { 
           
           steps {
               
               sh cd /var/lib/jenkins/workspace/k8s-test-basis/target 
              sh ‘‘‘
      REPOSITORY=172.18.0.218/codeflagtest/codeflag-basis:${BUILD_ID}
        pwd
        echo         FROM 172.18.0.218/codeflagtest/tomcat
      RUN rm -rf  /usr/local/tomcat/webapps/ROOT
        RUN /bin/cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime   && echo Asia/Shanghai >/etc/timezone 
          ADD target/basic-0.0.1-SNAPSHOT.war   /usr/local/tomcat/webapps/ROOT.war
         > Dockerfile
        docker build -t $REPOSITORY .
        docker login 172.18.0.218 -u admin -p  Harbor123456
        docker push $REPOSITORY
      
        ‘‘‘
           }
          
        }
                stage(deploy)     { 
          
           steps {
               sh  REPOSITORY=172.18.0.218/codeflagtest/codeflag-basis:${BUILD_ID}
              sh kubectl  get pod
              sh ‘‘‘
 cat << EOF > basis.yaml
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: basis
spec:
  replicas: 2
  selector:
    matchLabels:
      app: basis
  template:
    metadata:
      labels:
        app: basis
    spec:
      containers:
      - name: basis
        image: 172.18.0.218/codeflagtest/codeflag-basis:${BUILD_ID}
      
        imagePullPolicy: Always
        ports:
        - containerPort: 8080
        volumeMounts:
          - name: pvc-nas
            mountPath: "/home/www/test"
      volumes:
        - name: pvc-nas
          persistentVolumeClaim:
            claimName: pvc-nas
      imagePullSecrets:
        - name: registry-secret

---
apiVersion: v1
kind: Service
metadata:
  name: basis
spec:
  ports:
  - port: 80
    targetPort: 8080
    name: basis
  selector:
    app: basis
  type: LoadBalancer
EOF

kubectl apply -f basis.yaml
              
              ‘‘‘
              
           }
          
       }
    }

}

 技术图片

 

官方推荐样例:

技术图片

官方推荐的语法:

官方例子:
Jenkinsfile (Declarative Pipeline)
pipeline { 
    agent any 
    options {
        skipStagesAfterUnstable()
    }
    stages {
        stage(Build) { 
            steps { 
                sh make 
            }
        }
        stage(Test){
            steps {
                sh make check
                junit reports/**/*.xml 
            }
        }
        stage(Deploy) {
            steps {
                sh make publish
            }
        }
    }
}

 

jenkins自动化pipline的ci/cd流水线

标签:pull   tab   rop   ima   agent   one   port   lag   pipe   

原文地址:https://www.cnblogs.com/tigergaonotes/p/11316840.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!