From 2a01abd023fcc1b04ef0475f1cbf0c83b4f9d591 Mon Sep 17 00:00:00 2001 From: linzhongyan <1577714120@qq.com> Date: Tue, 28 Oct 2025 19:37:28 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E6=9B=B4=E6=96=B0Jenkins?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Jenkinsfile | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 72c6fc1..0e6ed96 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,27 +1,32 @@ pipeline { agent any - environment { - APP_HOME = "/opt/go-dy" - } + stages { stage('Checkout') { steps { - git url: 'http://47.95.203.241:3000/ReeseLin/golang-dy-back', branch: 'main', credentialsId: 'GITEA_CREDENTIAL_ID' + git url: 'http://47.95.203.241:3000/ReeseLin/golang-dy-back.git', + credentialsId: '932fcb89-1c39-4005-b664-15e862f09e20' } } - stage('Build Binary') { + + stage('Build Go Binary') { steps { - sh 'docker run --rm -v $APP_HOME:/app -w /app golang:1.22-alpine sh -c "go mod tidy && go build -o go-dy ."' + sh ''' + docker run --rm -v $PWD:/app -w /app golang:1.22-alpine \ + sh -c "go mod tidy && go build -o go-dy ." + ''' } } + stage('Build Docker Image') { steps { - sh 'docker build -t go-dy:latest $APP_HOME' + sh 'docker build -t go-dy:latest .' } } + stage('Deploy') { steps { - sh 'docker stop go-dy || true && docker rm go-dy || true && docker run -d --name go-dy -p 8090:18080 go-dy:latest' + sh 'docker run -d -p 8090:18080 --name go-dy go-dy:latest' } } }