diff --git a/Jenkinsfile b/Jenkinsfile index 229664b..efa3c05 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -2,7 +2,6 @@ pipeline { agent any environment { - DOCKER_HOST = "tcp://192.168.75.149:2375" DOCKER_IMAGE = "my-web-app:latest" K8S_DEPLOYMENT_NAME = "my-web-app-deployment" } @@ -12,9 +11,10 @@ pipeline { steps { script { try { - docker.build("${DOCKER_IMAGE}") + docker.image('docker:latest').inside { + sh "docker build -t ${DOCKER_IMAGE} ." + } } catch (Exception e) { - // 处理构建错误 echo "构建镜像失败: ${e.message}" currentBuild.result = 'FAILURE' error("构建失败") @@ -30,7 +30,6 @@ pipeline { docker.image("${DOCKER_IMAGE}").push() } } catch (Exception e) { - // 处理推送错误 echo "推送镜像失败: ${e.message}" currentBuild.result = 'FAILURE' error("推送失败") @@ -47,7 +46,6 @@ pipeline { kubeconfigId: 'K8S_CLUSTER_CONFIG' ) } catch (Exception e) { - // 处理部署错误 echo "部署到 Kubernetes 失败: ${e.message}" currentBuild.result = 'FAILURE' error("部署失败") @@ -59,7 +57,6 @@ pipeline { post { always { - // 清理工作 echo "完成" } success {