mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-22 15:25:49 +00:00
Edit Jenkinsfile
This commit is contained in:
parent
6bf56b2be3
commit
bc7b67fdae
1 changed files with 26 additions and 9 deletions
35
Jenkinsfile
vendored
35
Jenkinsfile
vendored
|
@ -4,36 +4,53 @@ pipeline {
|
|||
environment {
|
||||
GIT_COMMIT = sh(script: 'git rev-parse --short HEAD', returnStdout: true).trim()
|
||||
DOCKER_CREDS = credentials('docker_key')
|
||||
DOCKER_REPO = ''
|
||||
}
|
||||
|
||||
stages {
|
||||
stage ('Checkstyle') {
|
||||
stage('Set Docker Repository') {
|
||||
steps {
|
||||
sh 'mvn checkstyle:checkstyle'
|
||||
archiveArtifacts artifacts: 'target/checkstyle-report.xml', allowEmptyArchive: true
|
||||
script {
|
||||
if (env.BRANCH_NAME == 'main') {
|
||||
DOCKER_REPO = 'vkarpenko02/main'
|
||||
} else {
|
||||
DOCKER_REPO = 'vkarpenko02/mr'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
stage ('Test') {
|
||||
|
||||
stage('Checkstyle') {
|
||||
when { not { branch 'main' } } // Only for MR pipelines
|
||||
steps {
|
||||
sh 'mvn checkstyle:checkstyle'
|
||||
archiveArtifacts artifacts: 'target/site/checkstyle.html', allowEmptyArchive: true
|
||||
}
|
||||
}
|
||||
|
||||
stage('Test') {
|
||||
steps {
|
||||
sh 'mvn test'
|
||||
}
|
||||
}
|
||||
stage ('Build') {
|
||||
|
||||
stage('Build') {
|
||||
steps {
|
||||
sh 'mvn clean package -DskipTests'
|
||||
archiveArtifacts artifacts: 'target/*.jar', allowEmptyArchive: false
|
||||
}
|
||||
}
|
||||
stage ('Creating Docker image') {
|
||||
|
||||
stage('Create Docker Image') {
|
||||
steps {
|
||||
sh 'docker build -t vkarpenko02/mr:${GIT_COMMIT} .'
|
||||
sh 'docker build -t ${DOCKER_REPO}:${GIT_COMMIT} .'
|
||||
withCredentials([usernamePassword(credentialsId: 'docker_key', usernameVariable: 'DOCKER_HUB_USER', passwordVariable: 'DOCKER_HUB_PASS')]) {
|
||||
sh """
|
||||
echo ${DOCKER_HUB_PASS} | docker login -u ${DOCKER_HUB_USER} --password-stdin
|
||||
docker push vkarpenko02/mr:${GIT_COMMIT}
|
||||
docker push ${DOCKER_REPO}:${GIT_COMMIT}
|
||||
"""
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue