From e0ee927638b8a0b1db20d7a762c898def2bfa8f0 Mon Sep 17 00:00:00 2001 From: linzhongyan <1577714120@qq.com> Date: Tue, 28 Oct 2025 17:52:58 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E6=96=B0=E5=A2=9Ejenkis=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Jenkinsfile | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 Jenkinsfile diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..cdfaee6 --- /dev/null +++ b/Jenkinsfile @@ -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 '流水线失败,请检查日志' + } + } +}