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

Posted tigergaonotes

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了jenkins自动化pipline的ci/cd流水线相关的知识,希望对你有一定的参考价值。

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流水线的主要内容,如果未能解决你的问题,请参考以下文章

docker与jenkins的自动化CI/CD流水线实战

Jenkins自动化CI CD流水线之5--pipeline

CI/CD——构建企业级Docker+Jenkins+Git+Harbor流水线自动化持续集成持续发布平台

CI/CD——构建企业级Docker+Jenkins+Git+Harbor流水线自动化持续集成持续发布平台

docker与jenkins的自动化CI/CD流水线实战(svn)

今晚8点!JFrog DevOps 大讲堂如何使用 Jenkins 一步步搭建自动化 CI/CD 流水线?