mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-20 23:05:49 +00:00
Jenkinsfile update: moved to gradle build process.
Added docker repo and short commit hash variable. Added build parameters. Tagging sketch
This commit is contained in:
parent
e9397e0e35
commit
a70eb30506
1 changed files with 31 additions and 19 deletions
50
Jenkinsfile
vendored
50
Jenkinsfile
vendored
|
@ -3,15 +3,19 @@ pipeline {
|
||||||
agent any
|
agent any
|
||||||
|
|
||||||
environment {
|
environment {
|
||||||
NEXUS_CREDS = credentials('nexus-cred')
|
DOCKER_STORAGE = 'testfiesta/petclinic'
|
||||||
NEXUS_DOCKER_REPO_MR = '34.245.131.115:8085'
|
SHORT_COMMIT = "${GIT_COMMIT[0..7]}"
|
||||||
NEXUS_DOCKER_REPO_MAIN = '34.245.131.115:8084'
|
GIT_TAG = ''
|
||||||
}
|
}
|
||||||
|
|
||||||
tools {
|
tools {
|
||||||
gradle '8.7'
|
gradle '8.7'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
parameters {
|
||||||
|
choice(name: 'ACTION', choices: ['MR', 'Deploy'], description: 'Choose the action to perform')
|
||||||
|
}
|
||||||
|
|
||||||
stages {
|
stages {
|
||||||
// Merge request pipeline
|
// Merge request pipeline
|
||||||
stage('Checkstyle') {
|
stage('Checkstyle') {
|
||||||
|
@ -20,7 +24,7 @@ pipeline {
|
||||||
}
|
}
|
||||||
steps{
|
steps{
|
||||||
echo 'Running gradle checkstyle'
|
echo 'Running gradle checkstyle'
|
||||||
sh './gradlew checkstyleMain --no-daemon'
|
sh './gradlew check --no-daemon'
|
||||||
}
|
}
|
||||||
post {
|
post {
|
||||||
always {
|
always {
|
||||||
|
@ -34,7 +38,7 @@ pipeline {
|
||||||
}
|
}
|
||||||
steps {
|
steps {
|
||||||
echo 'Running gradle test'
|
echo 'Running gradle test'
|
||||||
sh './gradlew test -x test --no-daemon'
|
sh './gradlew test -x check --no-daemon'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
stage('Build') {
|
stage('Build') {
|
||||||
|
@ -52,7 +56,7 @@ pipeline {
|
||||||
}
|
}
|
||||||
steps {
|
steps {
|
||||||
echo 'Building docker Image'
|
echo 'Building docker Image'
|
||||||
sh 'docker build -t $NEXUS_DOCKER_REPO_MR/spring-petclinic:${GIT_COMMIT} .'
|
sh 'docker build -t $DOCKER_STORAGE:${SHORT_COMMIT} .'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
stage('Docker Login (MR)') {
|
stage('Docker Login (MR)') {
|
||||||
|
@ -60,12 +64,11 @@ pipeline {
|
||||||
changeRequest()
|
changeRequest()
|
||||||
}
|
}
|
||||||
steps {
|
steps {
|
||||||
echo 'Nexus Docker Repository Login'
|
echo 'Docker Repository Login'
|
||||||
script{
|
script{
|
||||||
withCredentials([usernamePassword(credentialsId: 'nexus-cred', usernameVariable: 'USER', passwordVariable: 'PASS' )]){
|
withCredentials([usernamePassword(credentialsId: 'docker-cred', usernameVariable: 'USER', passwordVariable: 'PASS' )]){
|
||||||
sh 'echo $PASS | docker login -u $USER --password-stdin $NEXUS_DOCKER_REPO_MR'
|
sh 'echo $PASS | docker login -u $USER --password-stdin $DOCKER_STORAGE'
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -74,19 +77,28 @@ pipeline {
|
||||||
changeRequest()
|
changeRequest()
|
||||||
}
|
}
|
||||||
steps {
|
steps {
|
||||||
echo 'Pushing Image to docker repo'
|
echo 'Pushing Image to Docker repository'
|
||||||
sh 'docker push $NEXUS_DOCKER_REPO_MR/spring-petclinic:${GIT_COMMIT}'
|
sh 'docker push $DOCKER_STORAGE:${SHORT_COMMIT}'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Main branch pipeline
|
// Main branch pipeline
|
||||||
|
stage('Git tag the current state') {
|
||||||
|
when {
|
||||||
|
branch 'main'
|
||||||
|
}
|
||||||
|
steps {
|
||||||
|
echo 'Tagging'
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
stage('Docker Build (Main)') {
|
stage('Docker Build (Main)') {
|
||||||
when {
|
when {
|
||||||
branch 'main'
|
branch 'main'
|
||||||
}
|
}
|
||||||
steps {
|
steps {
|
||||||
echo 'Building docker Image'
|
echo 'Building docker Image'
|
||||||
sh 'docker build -t $NEXUS_DOCKER_REPO_MAIN/spring-petclinic:${GIT_COMMIT} .'
|
sh 'docker build -t $DOCKER_STORAGE:${GIT_TAG} .'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
stage('Docker Login (Main)') {
|
stage('Docker Login (Main)') {
|
||||||
|
@ -94,10 +106,10 @@ pipeline {
|
||||||
branch 'main'
|
branch 'main'
|
||||||
}
|
}
|
||||||
steps {
|
steps {
|
||||||
echo 'Nexus Docker Repository Login'
|
echo 'Docker Repository Login'
|
||||||
script{
|
script{
|
||||||
withCredentials([usernamePassword(credentialsId: 'nexus-cred', usernameVariable: 'USER', passwordVariable: 'PASS' )]){
|
withCredentials([usernamePassword(credentialsId: 'docker-cred', usernameVariable: 'USER', passwordVariable: 'PASS' )]){
|
||||||
sh 'echo $PASS | docker login -u $USER --password-stdin $NEXUS_DOCKER_REPO_MAIN'
|
sh 'echo $PASS | docker login -u $USER --password-stdin $DOCKER_STORAGE'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -107,8 +119,8 @@ pipeline {
|
||||||
branch 'main'
|
branch 'main'
|
||||||
}
|
}
|
||||||
steps {
|
steps {
|
||||||
echo 'Pushing Image to docker repo'
|
echo 'Pushing Image to Docker repository'
|
||||||
sh 'docker push $NEXUS_DOCKER_REPO_MAIN/spring-petclinic:${GIT_COMMIT}'
|
sh 'docker push $DOCKER_STORAGE:${GIT_TAG}'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue