更新 'Jenkinsfile'

main
newrain001 9 months ago
parent cf329b8d24
commit 32c5a43c86
  1. 49
      Jenkinsfile

49
Jenkinsfile vendored

@ -10,16 +10,29 @@ pipeline {
stage('构建镜像') {
steps {
script {
docker.build("${docker_image}")
try {
docker.build("${docker_image}")
} catch (Exception e) {
// 处理构建错误
echo "构建镜像失败: ${e.message}"
currentBuild.result = 'FAILURE'
error("构建失败")
}
}
}
}
stage('推送镜像') {
steps {
script {
// 假设已经配置了 Docker 认证
docker.withRegistry('http://core.harbor.cn', 'registry-credentials') {
docker.image("${docker_image}").push()
try {
docker.withRegistry('http://core.harbor.cn', 'registry-credentials') {
docker.image("${docker_image}").push()
}
} catch (Exception e) {
// 处理推送错误
echo "推送镜像失败: ${e.message}"
currentBuild.result = 'FAILURE'
error("推送失败")
}
}
}
@ -27,13 +40,31 @@ pipeline {
stage('部署k8s') {
steps {
script {
kubernetesDeploy(
configs: 'k8s/deploy.yaml',
kubeconfigId: 'K8S_CLUSTER_CONFIG'
)
try {
kubernetesDeploy(
configs: 'k8s/deploy.yaml',
kubeconfigId: 'K8S_CLUSTER_CONFIG'
)
} catch (Exception e) {
// 处理部署错误
echo "部署到 Kubernetes 失败: ${e.message}"
currentBuild.result = 'FAILURE'
error("部署失败")
}
}
}
}
}
}
post {
always {
// 清理工作
}
success {
// 成功通知
}
failure {
// 失败通知
}
}
}

Loading…
Cancel
Save