Edit Jenkinsfile

This commit is contained in:
Viktoriia Karpenko 2024-12-20 12:41:29 +02:00
parent 93d23095c3
commit b63e92337f

12
Jenkinsfile vendored
View file

@ -8,38 +8,32 @@ pipeline {
stages {
stage ('Checkstyle') {
when { not { branch 'main' } }
steps {
sh 'mvn checkstyle:checkstyle'
archiveArtifacts artifacts: 'target/checkstyle-report.xml', allowEmptyArchive: true
}
}
stage ('Test') {
when { not { branch 'main' } }
steps {
sh 'mvn test'
}
}
stage ('Build') {
when { not { branch 'main' } }
steps {
sh 'mvn clean package -DskipTests'
archiveArtifacts artifacts: 'target/*.jar', allowEmptyArchive: false
}
}
stage ('Creating Docker Image') {
stage ('Creating Docker image') {
steps {
script {
def dockerRepo = branch == 'main' ? 'main' : 'mr'
sh "docker build -t vkarpenko02/${dockerRepo}:${GIT_COMMIT} ."
sh 'docker build -t vkarpenko02/mr:${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}
docker push vkarpenko02/mr:${GIT_COMMIT}
"""
}
}
}
}
}
}