feat:新增jenkis配置
This commit is contained in:
parent
d8d0ccbc91
commit
e0ee927638
57
Jenkinsfile
vendored
Normal file
57
Jenkinsfile
vendored
Normal file
@ -0,0 +1,57 @@
|
||||
pipeline {
|
||||
agent any
|
||||
|
||||
environment {
|
||||
GOOS = 'linux'
|
||||
GOARCH = 'amd64'
|
||||
APP_NAME = 'go-dy-linux-amd64'
|
||||
APP_PATH = '/opt/go-dy'
|
||||
DOCKER_NETWORK = 'go-dy-net'
|
||||
}
|
||||
|
||||
stages {
|
||||
stage('Checkout') {
|
||||
steps {
|
||||
git branch: 'main',
|
||||
url: 'http://47.95.203.241:3000/ReeseLin/golang-dy-back.git',
|
||||
credentialsId: '932fcb89-1c39-4005-b664-15e862f09e20' // 替换成你的凭据ID
|
||||
}
|
||||
}
|
||||
|
||||
stage('Build') {
|
||||
steps {
|
||||
sh '''
|
||||
go mod tidy
|
||||
go build -o ${APP_PATH}/${APP_NAME} ./...
|
||||
'''
|
||||
}
|
||||
}
|
||||
|
||||
stage('Deploy') {
|
||||
steps {
|
||||
sh '''
|
||||
docker stop go-dy || true
|
||||
docker rm go-dy || true
|
||||
docker run -d \
|
||||
--name 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 '流水线失败,请检查日志'
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user