更新 'Jenkinsfile'

main
newrain001 9 months ago
parent 52d6c46f77
commit ab36cbc23a
  1. 9
      Jenkinsfile

9
Jenkinsfile vendored

@ -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 {

Loading…
Cancel
Save