• <menu id="sssag"></menu>
  • <menu id="sssag"></menu>
  • Jenkins+Kubernetes+Docker完成微服務持續集成

    Jenkins+Kubernetes+Docker完成微服務持續集成

     

    拉取代碼,構建鏡像

    創建NFS共享目錄

    讓所有Jenkins-Slave構建指向NFS的Maven的共享倉庫目錄

    vi /etc/exports
    
    /opt/nfs/jenkins   *(rw,no_root_squash)
    /opt/nfs/maven    *(rw,no_root_squash)
    
    systemctl restart nfs	重啟NFS
    

    記得重啟nfs!

     

    然后

    注意:在構建過程會發現無法創建倉庫目錄,是因為NFS共享目錄權限不足,需更改權限

     

     

     

    然后就是去創建一個新項目:

     

    創建項目,編寫構建Pipeline

     

     

     

     

    配置一下harbor憑證

     

     

    然后再去編寫代碼:

    def git_address = "http://20.0.0.20:82/root/tensquare_back.git" 
    def git_auth = "904eff5d-41c8-44ad-ba24-7f539a0edb96"
    //構建版本的名稱
    def tag = "latest"
    //Harbor私服地址
    def harbor_url = "20.0.0.50:85"
    //Harbor的項目名稱
    def harbor_project_name = "tensquare"
    //Harbor的憑證
    def harbor_auth = "427399a8-db35-48e8-b5cf-a1ea63f10cc5"
    
    
    
    podTemplate(label: 'jenkins-slave', cloud: 'kubernetes', containers: [ 
            containerTemplate(
                name: 'jnlp',
                image: "20.0.0.50:85/library/jenkins-slave-maven:latest"
            ),
            containerTemplate( 
                name: 'docker',
                image: "docker:stable",
                ttyEnabled: true,
                command: 'cat'
            ),
        ],
        volumes: [
            hostPathVolume(mountPath: '/var/run/docker.sock', hostPath: '/var/run/docker.sock'),
            nfsVolume(mountPath: '/usr/local/apache-maven/repo', serverAddress: '20.0.0.10' , serverPath: '/opt/nfs/maven'),
        ],
    )
    {
    node("jenkins-slave"){
        // 第一步
        stage('pull code'){
            checkout([$class: 'GitSCM', branches: [[name: '*/master']], extensions: [], userRemoteConfigs: [[credentialsId: "${git_auth}", url: "${git_address}"]]])
        }
        // 第二步
        stage('make public sub project'){
            //編譯并安裝公共工程
            sh "mvn -f tensquare_common clean install"
        }
        // 第三步
        stage('make image'){
            //把選擇的項目信息轉為數組
            def selectedProjects = "${project_name}".split(',')
    
    
            for(int i=0;i<selectedProjects.size();i++){
                //取出每個項目的名稱和端口
                def currentProject = selectedProjects[i];
                //項目名稱
                def currentProjectName = currentProject.split('@')[0]
                //項目啟動端口
                def currentProjectPort = currentProject.split('@')[1]
    
                //定義鏡像名稱
                def imageName = "${currentProjectName}:${tag}"
    
                //編譯,構建本地鏡像
                sh "mvn -f ${currentProjectName} clean package dockerfile:build"
                container('docker') {
    
                    //給鏡像打標簽
                    sh "docker tag ${imageName} ${harbor_url}/${harbor_project_name}/${imageName}"
    
                    //登錄Harbor,并上傳鏡像
                    withCredentials([usernamePassword(credentialsId: "${harbor_auth}", passwordVariable: 'password', usernameVariable: 'username')])
                    {
                        //登錄
                        sh "docker login -u ${username} -p ${password} ${harbor_url}"
                        //上傳鏡像
                        sh "docker push ${harbor_url}/${harbor_project_name}/${imageName}"
                    }
    
                //刪除本地鏡像
                sh "docker rmi -f ${imageName}" 
                sh "docker rmi -f ${harbor_url}/${harbor_project_name}/${imageName}"
                }
            }
        }
    }
    }
    

      

    要修改地方:

     

     

    然后去構建看結果??!

     

    posted @ 2022-03-10 15:52  隱姓埋名4869  閱讀(11)  評論(0編輯  收藏  舉報
    国产在线码观看超清无码视频,人妻精品动漫H无码,十大看黄台高清视频,国产在线无码视频一区二区三区,国产男女乱婬真视频免费,免费看女人的隐私超爽,狠狠色狠狠色综合久久蜜芽