mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-25 08:35:49 +00:00
Edit Jenkinsfile
This commit is contained in:
parent
dc0ea24d45
commit
93d23095c3
1 changed files with 14 additions and 31 deletions
45
Jenkinsfile
vendored
45
Jenkinsfile
vendored
|
@ -4,58 +4,41 @@ pipeline {
|
||||||
environment {
|
environment {
|
||||||
GIT_COMMIT = sh(script: 'git rev-parse --short HEAD', returnStdout: true).trim()
|
GIT_COMMIT = sh(script: 'git rev-parse --short HEAD', returnStdout: true).trim()
|
||||||
DOCKER_CREDS = credentials('docker_key')
|
DOCKER_CREDS = credentials('docker_key')
|
||||||
DOCKER_REPO = '' // Default empty
|
|
||||||
}
|
}
|
||||||
|
|
||||||
stages {
|
stages {
|
||||||
stage('Set Docker Repository') {
|
stage ('Checkstyle') {
|
||||||
steps {
|
|
||||||
script {
|
|
||||||
if (env.BRANCH_NAME == 'main') {
|
|
||||||
DOCKER_REPO = 'vkarpenko02/main'
|
|
||||||
} else {
|
|
||||||
DOCKER_REPO = 'vkarpenko02/mr'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
echo "Docker repository set to: ${DOCKER_REPO}" // Debugging step
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
stage('Checkstyle') {
|
|
||||||
when { not { branch 'main' } }
|
when { not { branch 'main' } }
|
||||||
steps {
|
steps {
|
||||||
sh 'mvn checkstyle:checkstyle'
|
sh 'mvn checkstyle:checkstyle'
|
||||||
archiveArtifacts artifacts: 'target/site/checkstyle.html', allowEmptyArchive: true
|
archiveArtifacts artifacts: 'target/checkstyle-report.xml', allowEmptyArchive: true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
stage ('Test') {
|
||||||
stage('Test') {
|
when { not { branch 'main' } }
|
||||||
steps {
|
steps {
|
||||||
sh 'mvn test'
|
sh 'mvn test'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
stage ('Build') {
|
||||||
stage('Build') {
|
when { not { branch 'main' } }
|
||||||
steps {
|
steps {
|
||||||
sh 'mvn clean package -DskipTests'
|
sh 'mvn clean package -DskipTests'
|
||||||
archiveArtifacts artifacts: 'target/*.jar', allowEmptyArchive: false
|
archiveArtifacts artifacts: 'target/*.jar', allowEmptyArchive: false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
stage ('Creating Docker Image') {
|
||||||
stage('Create Docker Image') {
|
|
||||||
steps {
|
steps {
|
||||||
script {
|
script {
|
||||||
if (!DOCKER_REPO) {
|
def dockerRepo = branch == 'main' ? 'main' : 'mr'
|
||||||
error "DOCKER_REPO is not set. Ensure the repository is configured for the current branch."
|
sh "docker build -t vkarpenko02/${dockerRepo}:${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/${dockerRepo}:${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 ${DOCKER_REPO}:${GIT_COMMIT}
|
|
||||||
"""
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue