jenkins pipeline静态节点和动态slave结合使用

使用场景构建代码是更快,动态slave 将快速连接到aws eks 就不用配置key

pipeline {
    agent none

    options{
    timestamps ()
    disableConcurrentBuilds()
    buildDiscarder(logRotator(numToKeepStr: '10'))
}
    environment {

        image = "registry.com/neway-sz/uat:$JOB_NAME$BUILD_ID"
    }
      parameters {
    string(name: 'BRANCH', defaultValue: 'master', description: 'Enter the branch name')
  }

    stages {
        stage('Get Code') {
            agent {
                label 'slave-01'
            }
	
             steps {
            script {
            def branch = params.BRANCH
            checkout scmGit(branches: [[name: '*/${branch}']], extensions: [], userRemoteConfigs: [[credentialsId: 'git', url: 'http://gitlab/web.git']])

            }
        }
	}
	
        stage("Docker Build") {
            agent {
                label 'slave-01'
            }
            steps {
                script {
				   sh "sed -i 's|node:20.5.1 | hub.exchangs.top/sit/node:2021 |' Dockerfile-rc"
                    withDockerRegistry(credentialsId: 'nw', url: 'https://registry.com') {
                        docker.build("${image}", "-f Dockerfile-rc  .").push()
                        sh "docker rmi ${image}"
                    }
                }
            }
        }

        stage('Deploy to AWS EKS') {
            agent {
                kubernetes {
                    inheritFrom 'devops'
                }
            }
            steps {
                container('abpay') {
				     sh 'aws eks update-kubeconfig --name  Pay01  --region ap-northeast-1'
                    sh 'kubectl get pods -n default'
                   
					sh "kubectl -n default set image deployment/manage-web manage-web=${image}"
                }
            }
        }
      }  
	}

你可能感兴趣的:(Jenkins,jenkins)