nexus deploy

This commit is contained in:
kirill.labutin 2026-08-14 14:49:49 +03:00
parent 743d9f0894
commit 60c8265afc
1 changed files with 34 additions and 1 deletions

35
Jenkinsfile vendored
View File

@ -6,9 +6,15 @@ String extractBaseVersion(String pom) {
return matcher.find() ? matcher.group(1) : null return matcher.find() ? matcher.group(1) : null
} }
pipeline { pipeline {
agent any agent any
environment {
NEXUS_URL = 'http://172.16.0.59:8081/repository/docker/'
NEXUS_CREDENTIALS_ID = 'nexus_cred'
}
stages { stages {
stage('Set build number into version') { stage('Set build number into version') {
steps { steps {
@ -43,7 +49,31 @@ pipeline {
sh "docker build -f Dockerfile -t pfsdn:${VERSION} ." sh "docker build -f Dockerfile -t pfsdn:${VERSION} ."
echo "Saving docker image pfsdn:${VERSION}" echo "Saving docker image pfsdn:${VERSION}"
sh "docker save pfsdn:${VERSION} | gzip > pfsdn-${VERSION}.tar.gz" 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 { post {
always {
sh "docker rmi pfsdn:${VERSION} || true"
}
success { success {
cleanWs() cleanWs()
} }