From e4f596dd828b6ca2cd800ddfad1dc5ae992dc57b Mon Sep 17 00:00:00 2001 From: dl Date: Wed, 4 Feb 2026 12:03:16 +0500 Subject: [PATCH] Docker automate in Jenkinsfile --- Jenkinsfile | 95 +++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 77 insertions(+), 18 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index bb492eb..56b8747 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,23 +1,82 @@ pipeline { - agent { label 'agent_smith' } - - stages { - stage('Stop and Remove Existing Container') { - steps { - sh ''' - docker stop open_sesam || true - docker rm open_sesam || true - docker-compose down || true - ''' - } + agent { + node { + label "agent_smith" + docker { + image "docker:stable" + } + } } - stage('Build and Run Container') { - steps { - sh ''' - docker-compose up --build -d - ''' - } + environment { + REGISTRY_URL = "https://proxy.docker.dataekb.ru/harbor/projects/3/repositories" + IMAGE_NAME = "open_sesam" + IMAGE_TAG = "latest" + } + + stages { + stage("Build Docker Image") { + steps { + script { + docker.build("${IMAGE_NAME}:${IMAGE_TAG}") + } + } + } + + stage('Push to Harbor') { + steps { + script { + docker.withRegistry("{REGISTRY_URL}", "harbor-credentials") { + docker.image("${IMAGE_NAME}:${IMAGE_TAG}").push() + } + } + } + } + + stage("Deploy") { + steps { + script { + sh ''' + docker-compose pull + docker-compose up -d + ''' + } + } + } + } + + post { + failure { + echo "[ERROR] Build failure" + } + success { + echo "[OK] Build success" + } } - } } + + +// Old_version +// pipeline { +// agent { label 'agent_smith' } +// +// stages { +// stage('Stop and Remove Existing Container') { +// steps { +// sh ''' +// docker stop open_sesam || true +// docker rm open_sesam || true +// docker-compose down || true +// ''' +// } +// } +// +// stage('Build and Run Container') { +// steps { +// sh ''' +// docker-compose up --build -d +// ''' +// } +// } +// } +// }