在这里插入图片描述
在这里插入图片描述

  • docker编译使用的groovy脚本

package org.devops

def docker_bui() {
    withCredentials([usernamePassword(credentialsId: 'dockeropa', passwordVariable: 'Password', usernameVariable: 'Username')]) {
       sh '''
       docker login -u$Username -p$Password kk.jsj.com
       docker build -t ${name}:${BUILD_ID} .
       docker tag  ${name}:${BUILD_ID} ${image}
       docker push ${image}
       echo ${image}
       docker rmi ${image}
       docker rmi ${name}:${BUILD_ID}
       echo ${name}:${BUILD_ID}  
        '''
    }
   }
  • deploy编译使用的groovy脚本

package org.devops

def test_kue() {
     withKubeConfig([credentialsId:'kj8s',namespace:'default']) {
     sh ' echo "10.0" >> /etc/hosts'
     sh "sed -i 's#{{image}}#${image}#g' k8s.yaml"
     sh 'kubectl apply -f k8s.yaml'
     }   

}
  • Jenkinsfile

@Library ("jr-shared-library") _
def docker_test_bui = new org.devops.docker_test_bui()
def deploy_test = new org.devops.deploy_test()

pipeline {
   environment {
    name="portal"
    image="JSS.com/libary/jr-prod-01:${name}$BUILD_ID"
        }
    agent { 
     kubernetes {
       inheritFrom 'maven-test'
      }
       } 
         
    options{ 
      timestamps ()
      disableConcurrentBuilds () 
      buildDiscarder(logRotator(numToKeepStr: '10'))       
    }
    
    stages {
      stage('Get Code') {
        steps {  
  checkout([$class: 'GitSCM', branches: [[name: '*/sit']], extensions: [], userRemoteConfigs: [[credentialsId: 'vip', url: 'https://gitHUB.OOOX.com/youhuomenhu/backend.git']]])
          }
             }
             
        stage('Java-build') {
            steps {       
                container('maven36'){
                    sh 'mvn clean package'
                
                }
            }
        }
        
      stage('Docker-build') {
            steps {       
                container('docker'){
                 script {
                    docker_test_bui.docker_bui()
                } 
            }
        }
      }
      
      stage('Deploy....') {
        steps {       
        container('kubectl'){
          script {
             deploy_test.test_kue()
               }
                 }
                    }
                        }

                            }
                            //消息推送
                           post {
                              always {         
                                 pushplus ("001")
                                    }
                            }
                   }
Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐