From 60c8265afc48bb69e86e7be22a3c052f7ac2c174 Mon Sep 17 00:00:00 2001 From: "kirill.labutin" Date: Fri, 14 Aug 2026 14:49:49 +0300 Subject: [PATCH] nexus deploy --- Jenkinsfile | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 824ad22..143be1f 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -6,9 +6,15 @@ String extractBaseVersion(String pom) { return matcher.find() ? matcher.group(1) : null } + pipeline { agent any + environment { + NEXUS_URL = 'http://172.16.0.59:8081/repository/docker/' + NEXUS_CREDENTIALS_ID = 'nexus_cred' + } + stages { stage('Set build number into version') { steps { @@ -43,7 +49,31 @@ pipeline { sh "docker build -f Dockerfile -t pfsdn:${VERSION} ." echo "Saving docker image pfsdn:${VERSION}" sh "docker save pfsdn:${VERSION} | gzip > pfsdn-${VERSION}.tar.gz" - sh "docker rmi pfsdn:${VERSION} || true" + } + } + + stage('Push docker image to Nexus') { + steps { + script { + def nexusHost = NEXUS_URL + .replaceAll(/^https?:\/\//, '') + .replaceAll(/\/+$/, '') + def nexusImage = "${nexusHost}/pfsdn:${VERSION}" + + withCredentials([usernamePassword( + credentialsId: NEXUS_CREDENTIALS_ID, + usernameVariable: 'NEXUS_USER', + passwordVariable: 'NEXUS_PASS' + )]) { + sh """ + echo "\${NEXUS_PASS}" | docker login ${nexusHost} -u "\${NEXUS_USER}" --password-stdin + docker tag pfsdn:${VERSION} ${nexusImage} + docker push ${nexusImage} + docker rmi ${nexusImage} || true + docker rmi pfsdn:${VERSION} || true + """ + } + } } } @@ -63,6 +93,9 @@ pipeline { } post { + always { + sh "docker rmi pfsdn:${VERSION} || true" + } success { cleanWs() }