mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-19 06:15:50 +00:00
added Jenkinsfile
This commit is contained in:
parent
2dcecd50a8
commit
4b0114f5a8
1 changed files with 106 additions and 0 deletions
106
Jenkinsfile
vendored
Normal file
106
Jenkinsfile
vendored
Normal file
|
@ -0,0 +1,106 @@
|
|||
pipeline {
|
||||
agent any
|
||||
|
||||
environment {
|
||||
REPO_MR = "mr"
|
||||
REPO_MAIN = "main"
|
||||
IMAGE_NAME = "spring-petclinic"
|
||||
}
|
||||
|
||||
stages {
|
||||
stage ('Checkout') {
|
||||
when {
|
||||
expression { env.CHANGE_ID != null }
|
||||
}
|
||||
steps {
|
||||
checkout scm
|
||||
}
|
||||
}
|
||||
|
||||
stage ('Checkstyle') {
|
||||
when {
|
||||
expression { env.CHANGE_ID != null }
|
||||
}
|
||||
steps {
|
||||
script {
|
||||
sh 'mvn checkstyle:checkstyle'
|
||||
}
|
||||
}
|
||||
post {
|
||||
always {
|
||||
archiveArtifacts artifacts: '**/checkstyle-result.xml'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
stage ('Test') {
|
||||
when {
|
||||
expression { env.CHANGE_ID != null }
|
||||
}
|
||||
steps {
|
||||
script {
|
||||
sh 'mvn test'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
stage ('Build') {
|
||||
when {
|
||||
expression { env.CHANGE_ID != null }
|
||||
}
|
||||
steps {
|
||||
script {
|
||||
sh 'mvn clean install -DskipTests'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
stage ('Docker Image for MR') {
|
||||
when {
|
||||
expression { env.CHANGE_ID != null }
|
||||
}
|
||||
steps {
|
||||
script {
|
||||
def shortCommit = env.GIT_COMMIT.substring(0, 7)
|
||||
withCredentials([usernamePassword(
|
||||
credentialsId: 'docker-credentials',
|
||||
usernameVariable: 'DOCKER_CREDS_USR',
|
||||
passwordVariable: 'DOCKER_CREDS_PSW'
|
||||
)]) {
|
||||
sh """
|
||||
echo "${DOCKER_CREDS_PSW}" | docker login localhost:8084 -u "${DOCKER_CREDS_USR}" --password-stdin
|
||||
docker build -t ${IMAGE_NAME}:${shortCommit} .
|
||||
docker tag ${IMAGE_NAME}:${shortCommit} localhost:8084/repository/${REPO_MR}/${IMAGE_NAME}:${shortCommit}
|
||||
docker push localhost:8084/repository/${REPO_MR}/${IMAGE_NAME}:${shortCommit}
|
||||
"""
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
stage ('Docker Image for main branch') {
|
||||
when {
|
||||
expression {
|
||||
env.BRANCH_NAME == 'origin/main' || env.GIT_BRANCH?.contains('main')
|
||||
}
|
||||
}
|
||||
steps {
|
||||
script {
|
||||
def shortCommit = env.GIT_COMMIT.substring(0, 7)
|
||||
withCredentials([usernamePassword(
|
||||
credentialsId: 'docker-credentials',
|
||||
usernameVariable: 'DOCKER_CREDS_USR',
|
||||
passwordVariable: 'DOCKER_CREDS_PSW'
|
||||
)]) {
|
||||
sh """
|
||||
echo "${DOCKER_CREDS_PSW}" | docker login localhost:8085 -u "${DOCKER_CREDS_USR}" --password-stdin
|
||||
docker build -t ${IMAGE_NAME}:${shortCommit} .
|
||||
docker tag ${IMAGE_NAME}:${shortCommit} localhost:8085/repository/${REPO_MAIN}/${IMAGE_NAME}:${shortCommit}
|
||||
docker push localhost:8085/repository/${REPO_MAIN}/${IMAGE_NAME}:${shortCommit}
|
||||
"""
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue