pipeline { agent any environment { DOCKER_IMAGE = "my-web-app:latest" K8S_DEPLOYMENT_NAME = "my-web-app-deployment" } stages { stage('构建镜像') { steps { script { docker.build("${DOCKER_IMAGE}") } } } stage('推送镜像') { steps { script { // 假设已经配置了 Docker 认证 docker.withRegistry('http://core.harbor.cn', 'registry-credentials') { docker.image("${DOCKER_IMAGE}").push() } } } } stage('部署k8s') { steps { script { kubernetesDeploy( configs: 'k8s/deploy.yaml', kubeconfigId: 'K8S_CLUSTER_CONFIG' ) } } } } }