feat:流水线

This commit is contained in:
linzhongyan 2025-10-28 18:32:12 +08:00
parent 54600d2f6d
commit 50e9f7b741

47
Jenkinsfile vendored
View File

@ -1,61 +1,26 @@
pipeline { pipeline {
agent { agent any
docker {
image 'golang:1.22-alpine'
}
}
environment {
GOOS = 'linux'
GOARCH = 'amd64'
APP_NAME = 'go-dy-linux-amd64'
APP_PATH = '/opt/go-dy'
DOCKER_NETWORK = 'go-dy-net'
}
stages { stages {
stage('Checkout') { stage('Checkout') {
steps { steps {
git branch: 'main', git branch: 'main', url: 'http://47.95.203.241:3000/ReeseLin/golang-dy-back.git'
url: 'http://47.95.203.241:3000/ReeseLin/golang-dy-back.git',
credentialsId: '932fcb89-1c39-4005-b664-15e862f09e20' // 替换成你的凭据ID
} }
} }
stage('Build') { stage('Build') {
steps { steps {
sh ''' sh 'go mod tidy'
go mod tidy sh 'go build -o go-dy .'
go build -o ${APP_PATH}/${APP_NAME} ./...
'''
} }
} }
stage('Deploy') { stage('Deploy') {
steps { steps {
sh ''' sh '''
docker stop go-dy || true docker stop go-dy || true
docker rm go-dy || true docker rm go-dy || true
docker run -d \ docker build -t go-dy .
--name go-dy \ docker run -d --name go-dy -p 8090:18080 go-dy
--restart=always \
--network ${DOCKER_NETWORK} \
-p 8090:18080 \
-v ${APP_PATH}/${APP_NAME}:/app/go-dy \
-v ${APP_PATH}/.env:/app/.env \
--workdir /app \
golang:1.22-alpine ./go-dy
''' '''
} }
} }
} }
post {
success {
echo '部署成功!'
}
failure {
echo '流水线失败,请检查日志'
}
}
} }