Second pipeline for main branch

This commit is contained in:
JustFiesta 2024-05-02 18:06:38 +02:00
parent ebfebd789d
commit a83ea1684e

55
Jenkinsfile vendored
View file

@ -4,7 +4,6 @@ pipeline {
environment {
NEXUS_CREDS = credentials('nexus-cred')
NEXUS_DOCKER_REPO_MR = '34.241.46.54:8085'
NEXUS_DOCKER_REPO_MAIN = '34.241.46.54:8084'
}
tools {
@ -35,8 +34,7 @@ pipeline {
sh './gradlew build -x test -x check -x checkFormat -x processTestAot --no-daemon'
archiveArtifacts artifacts: 'build/libs/*.jar', fingerprint: true }
}
stage('Docker Build') {
stage('Docker Build (MR)') {
steps {
echo 'Building docker Image'
sh 'docker build -t $NEXUS_DOCKER_REPO_MR/spring-petclinic:${GIT_COMMIT} .'
@ -53,7 +51,7 @@ pipeline {
}
}
}
stage('Docker Push') {
stage('Docker Push (MR)') {
steps {
echo 'Pushing Image to docker hub'
sh 'docker push $NEXUS_DOCKER_REPO_MR/spring-petclinic:${GIT_COMMIT}'
@ -67,3 +65,52 @@ pipeline {
}
}
}
// Main branch pipeline
pipeline {
agent any
environment {
NEXUS_CREDS = credentials('nexus-cred')
NEXUS_DOCKER_REPO_MAIN = '34.241.46.54:8084'
}
stage('Docker Build (Main)') {
when {
branch 'main'
}
steps {
echo 'Building docker Image'
sh 'docker build -t $NEXUS_DOCKER_REPO_MAIN/spring-petclinic:${GIT_COMMIT} .'
}
}
stage('Docker Login') {
when {
branch 'main'
}
steps {
echo 'Nexus Docker Repository Login'
script{
withCredentials([usernamePassword(credentialsId: 'nexus-cred', usernameVariable: 'USER', passwordVariable: 'PASS' )]){
sh 'echo $PASS | docker login -u $USER --password-stdin $NEXUS_DOCKER_REPO_MAIN'
}
}
}
}
stage('Docker Push (Main)') {
when {
branch 'main'
}
steps {
echo 'Pushing Image to docker hub'
sh 'docker push $NEXUS_DOCKER_REPO_MAIN/spring-petclinic:${GIT_COMMIT}'
}
}
post {
always {
cleanWs()
}
}
}