Update Jenkinsfile

This commit is contained in:
Marija Stopa 2025-01-17 15:19:06 +01:00 committed by GitHub
parent bf9c181775
commit 592b7338f9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

53
Jenkinsfile vendored
View file

@ -4,35 +4,50 @@ pipeline {
DOCKER_CREDENTIALS_ID = 'dockerhub-credentials'
}
stages {
// stage('Checkstyle') {
// steps {
// sh './mvnw checkstyle:checkstyle'
// archiveArtifacts artifacts: 'target/checkstyle-result.xml', fingerprint: true
// }
// }
// stage('Test') {
// steps {
// sh './mvnw test'
// }
// }
// stage('Build') {
// steps {
// sh './mvnw clean package -DskipTests'
// }
// }
stage('Checkstyle') {
when {
expression { env.BRANCH_NAME != 'main' }
}
steps {
sh './mvnw checkstyle:checkstyle'
archiveArtifacts artifacts: 'target/checkstyle-result.xml', fingerprint: true
}
}
stage('Test') {
when {
expression { env.BRANCH_NAME != 'main' }
}
steps {
sh './mvnw test'
}
}
stage('Build') {
when {
expression { env.BRANCH_NAME != 'main' }
}
steps {
sh './mvnw clean package -DskipTests'
}
}
stage('Create Docker Image') {
steps {
script {
withCredentials([usernamePassword(credentialsId: "${DOCKER_CREDENTIALS_ID}", usernameVariable: 'DOCKER_USERNAME', passwordVariable: 'DOCKER_PASSWORD')]) {
def repoName = env.BRANCH_NAME == 'main' ? 'main-jenkins' : 'mr-jenkins'
def tag = env.GIT_COMMIT?.substring(0, 7) ?: 'latest'
sh """
docker login -u \$DOCKER_USERNAME --password \$DOCKER_PASSWORD
docker build -t marijastopa/mr-jenkins:blabla .
docker push marijastopa/mr-jenkins:blabla
docker build -t marijastopa/${repoName}:${tag} .
docker push marijastopa/${repoName}:${tag}
"""
}
}
}
}
}
post {
always {
echo "Pipeline execution completed."
}
}
}