修改jenkinsfile

This commit is contained in:
wangtianqi 2025-06-25 13:45:31 +08:00
parent 0f52893ddf
commit 9caa5c3b58

34
Jenkinsfile vendored
View File

@ -1,9 +1,10 @@
pipeline {
agent any
// 声明使用Jenkins配置的Go工具
tools {
go 'go' // 修正:使用小写的'go'与Jenkins配置的工具名称一致
// 使用Docker代理来提供稳定的Go环境避免网络下载问题
agent {
docker {
image 'golang:1.21-alpine'
args '-v /var/run/docker.sock:/var/run/docker.sock'
}
}
options {
@ -32,6 +33,22 @@ pipeline {
}
stages {
stage('环境准备') {
steps {
echo '🔧 准备Docker环境...'
sh '''
# 安装Docker客户端和其他必要工具
apk add --no-cache docker-cli curl wget git ca-certificates tzdata
# 验证Go和Docker环境
go version
docker --version
echo "✅ 环境准备完成"
'''
}
}
stage('Checkout') {
steps {
echo '🔄 开始检出代码...'
@ -226,6 +243,7 @@ EOF
stage('构建Docker镜像') {
steps {
echo '🐳 构建Docker镜像...'
echo '💡 提示通过Docker socket在容器内访问主机Docker守护进程'
script {
try {
// 清理旧镜像
@ -422,6 +440,7 @@ EOF
post {
always {
node {
script {
echo '🧹 清理工作空间...'
try {
@ -445,6 +464,7 @@ EOF
}
}
}
}
success {
script {
@ -475,6 +495,7 @@ EOF
}
failure {
node {
script {
echo '❌ 流水线执行失败!'
def message = """
@ -499,8 +520,10 @@ EOF
'''
}
}
}
cleanup {
node {
script {
try {
// 清理工作空间
@ -512,4 +535,5 @@ EOF
}
}
}
}
}