pipeline { agent { kubernetes { yamlFile 'deploy/KubernetesPod.yaml' retries 2 } } environment { IMAGE_REPO = "registry.cn-hangzhou.aliyuncs.com/sxtest" TAB = "\n \n " BUILD_TASKS = "\n \n " } stages{ stage('构建镜像') { steps { container('docker') { echo "构建 Docker 镜像阶段" sh 'echo "nameserver 114.114.114.114" >> /etc/resolv.conf' sh 'docker build --target image-idcprod -t ${IMAGE_REPO}/aihub-backend:sxtest --output type=docker .' echo "build success" } script { env.BUILD_TASKS += env.STAGE_NAME + "✅" + env.TAB } } } stage('镜像推送') { steps { container('docker') { echo "Push Docker 镜像阶段" sh'docker images' sh 'docker push ${IMAGE_REPO}/aihub-backend:sxtest ' echo "Push image success" } script { env.BUILD_TASKS += env.STAGE_NAME + "✅" + env.TAB } } } stage('重启服务') { steps { container('kubectl') { sh 'kubectl version' } script { env.BUILD_TASKS += env.STAGE_NAME + "✅" + env.TAB } sh 'printenv' } } } }