From 854817e0c470677d8694676c5cd957184517dcb8 Mon Sep 17 00:00:00 2001 From: chenchun Date: Wed, 6 May 2026 16:42:32 +0800 Subject: [PATCH] =?UTF-8?q?ci:=20=E6=B7=BB=E5=8A=A0=20Jenkinsfile=20?= =?UTF-8?q?=E7=94=A8=E4=BA=8E=E6=9E=84=E5=BB=BA=E3=80=81=E6=8E=A8=E9=80=81?= =?UTF-8?q?=E5=92=8C=E9=83=A8=E7=BD=B2=20Docker=20=E9=95=9C=E5=83=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Jenkinsfile | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 Jenkinsfile diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..946096e --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,66 @@ +pipeline { + agent any + + environment { + REGISTRY = 'git.virtheart.com' + REGISTRY_OWNER = 'virtheart' + REGISTRY_USERNAME = 'chenchun@virtheart.com' + IMAGE_NAME = "${env.JOB_NAME.replace(' ', '-').toLowerCase()}" + IMAGE_TAG = "${env.BUILD_NUMBER}" + } + + stages { + stage('Checkout') { + steps { + checkout scm + } + } + + stage('Build Image') { + steps { + script { + def imageFullName = "${REGISTRY}/${REGISTRY_OWNER}/${IMAGE_NAME}:${IMAGE_TAG}" + sh """ + docker build -t ${imageFullName} . + """ + } + } + } + + stage('Push Image') { + steps { + withCredentials([usernamePassword(credentialsId: 'docker-registry-credentials', usernameVariable: 'REGISTRY_USERNAME', passwordVariable: 'REGISTRY_PASSWORD')]) { + script { + def imageFullName = "${REGISTRY}/${REGISTRY_OWNER}/${IMAGE_NAME}:${IMAGE_TAG}" + sh """ + echo ${REGISTRY_PASSWORD} | docker login ${REGISTRY} -u ${REGISTRY_USERNAME} --password-stdin + docker push ${imageFullName} + docker rmi ${imageFullName} + """ + } + } + } + } + + stage('Deploy Container') { + steps { + script { + def imageFullName = "${REGISTRY}/${REGISTRY_OWNER}/${IMAGE_NAME}:${IMAGE_TAG}" + sh """ + docker stop ${IMAGE_NAME} || true + docker rm ${IMAGE_NAME} || true + docker run -d --name ${IMAGE_NAME} \ + --restart unless-stopped \ + ${imageFullName} + """ + } + } + } + } + + post { + always { + cleanWs() + } + } +} \ No newline at end of file