mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-21 07:15:49 +00:00
Jenkinsfile for building and pushing Docker image to Nexus Docker repo
This commit is contained in:
parent
664a740b9a
commit
73d1376a73
1 changed files with 27 additions and 22 deletions
49
Jenkinsfile
vendored
49
Jenkinsfile
vendored
|
@ -1,32 +1,37 @@
|
|||
pipeline {
|
||||
agent any
|
||||
|
||||
tools {
|
||||
// Install the Maven version configured as "M3" and add it to the path.
|
||||
gradle "8.6"
|
||||
environment {
|
||||
NEXUS_CREDS = credentials('nexus-cred')
|
||||
NEXUS_DOCKER_REPO = '3.252.205.41:8085'
|
||||
}
|
||||
|
||||
stages {
|
||||
stage('Build') {
|
||||
|
||||
stage('Docker Build') {
|
||||
|
||||
steps {
|
||||
echo 'Building docker Image'
|
||||
sh 'docker build -t $NEXUS_DOCKER_REPO/spring-petclinic:${GIT_COMMIT} .'
|
||||
}
|
||||
}
|
||||
|
||||
stage('Docker Login') {
|
||||
steps {
|
||||
// Get some code from a GitHub repository
|
||||
git 'https://github.com/jglick/simple-maven-project-with-tests.git'
|
||||
|
||||
// Run Maven on a Unix agent.
|
||||
sh "mvn -Dmaven.test.failure.ignore=true clean package"
|
||||
|
||||
// To run Maven on a Windows agent, use
|
||||
// bat "mvn -Dmaven.test.failure.ignore=true clean package"
|
||||
}
|
||||
|
||||
post {
|
||||
// If Maven was able to run the tests, even if some of the test
|
||||
// failed, record the test results and archive the jar file.
|
||||
success {
|
||||
junit '**/target/surefire-reports/TEST-*.xml'
|
||||
archiveArtifacts 'target/*.jar'
|
||||
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'
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
stage('Docker Push') {
|
||||
steps {
|
||||
echo 'Pushing Imgaet to docker hub'
|
||||
sh 'docker push $NEXUS_DOCKER_REPO/spring-petclinic:${GIT_COMMIT}'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue