Create Jenkinsfile

This commit is contained in:
MihailInternul 2024-02-15 15:16:15 +02:00 committed by GitHub
parent c030f213e6
commit 54992166d1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

62
Jenkinsfile vendored Normal file
View file

@ -0,0 +1,62 @@
pipeline {
agent any
stages {
stage('Checkstyle') {
when {
expression { env.CHANGE_TARGET ==~ /^merge$/ }
}
steps {
// Use Maven checkstyle plugin to generate a code style report
sh 'mvn checkstyle:checkstyle'
archiveArtifacts artifacts: '**/target/checkstyle-result.xml', fingerprint: true
}
}
stage('Test') {
when {
expression { env.CHANGE_TARGET ==~ /^merge$/ }
}
steps {
// Run tests with Maven
sh 'mvn test'
}
}
stage('Build') {
when {
expression { env.CHANGE_TARGET ==~ /^merge$/ }
}
steps {
// Build without tests with Maven
sh 'mvn clean package -DskipTests'
}
}
stage('Create Docker Image MR') {
when {
expression { env.CHANGE_TARGET ==~ /^merge$/ }
}
steps {
// Build Docker image from Dockerfile
script {
def gitCommitShort = sh(script: 'git rev-parse --short HEAD', returnStdout: true).trim()
def dockerImage = "mihailinternul/mr:${gitCommitShort}"
sh "docker build -t ${dockerImage} ."
sh "docker push ${dockerImage}"
}
}
}
stage('Create Docker Image Main') {
when {
expression { env.CHANGE_TARGET ==~ /^main$/ }
}
steps {
// Build Docker image from Dockerfile
script {
def gitCommitShort = sh(script: 'git rev-parse --short HEAD', returnStdout: true).trim()
def dockerImage = "mihailinternul/main:${gitCommitShort}"
sh "docker build -t ${dockerImage} ."
sh "docker push ${dockerImage}"
}
}
}
}
}