mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-23 15:55:49 +00:00
Update Jenkinsfile
This commit is contained in:
parent
4e50b1a557
commit
1adcfae45c
1 changed files with 14 additions and 41 deletions
55
Jenkinsfile
vendored
55
Jenkinsfile
vendored
|
@ -1,65 +1,38 @@
|
|||
pipeline {
|
||||
agent any
|
||||
|
||||
environment {
|
||||
GIT_COMMIT_SHORT = sh(script: "git rev-parse --short HEAD", returnStdout: true).trim()
|
||||
DOCKER_CREDENTIALS_ID = 'dockerhub-credentials'
|
||||
DOCKERHUB_USER = 'marijastopa'
|
||||
DOCKERHUB_REPO_MAIN = 'main-jenkins'
|
||||
DOCKERHUB_REPO_MR = 'mr-jenkins'
|
||||
agent {
|
||||
docker {
|
||||
image 'docker:latest'
|
||||
args '--privileged -v /var/lib/docker'
|
||||
}
|
||||
}
|
||||
environment {
|
||||
DOCKER_CREDENTIALS_ID = 'dockerhub-credentials'
|
||||
}
|
||||
|
||||
stages {
|
||||
stage('Checkstyle') {
|
||||
when {
|
||||
not {
|
||||
branch 'main'
|
||||
}
|
||||
}
|
||||
steps {
|
||||
echo 'Running Checkstyle...'
|
||||
sh './mvnw checkstyle:checkstyle'
|
||||
archiveArtifacts artifacts: 'target/site/checkstyle.html', allowEmptyArchive: true
|
||||
archiveArtifacts artifacts: 'target/checkstyle-result.xml', fingerprint: true
|
||||
}
|
||||
}
|
||||
|
||||
stage('Test') {
|
||||
when {
|
||||
not {
|
||||
branch 'main'
|
||||
}
|
||||
}
|
||||
steps {
|
||||
echo 'Running Tests...'
|
||||
sh './mvnw clean test'
|
||||
sh './mvnw test'
|
||||
}
|
||||
}
|
||||
|
||||
stage('Build') {
|
||||
when {
|
||||
not {
|
||||
branch 'main'
|
||||
}
|
||||
}
|
||||
steps {
|
||||
echo 'Building application...'
|
||||
sh './mvnw clean package -DskipTests'
|
||||
}
|
||||
}
|
||||
|
||||
stage('Create Docker Image') {
|
||||
steps {
|
||||
echo 'Creating Docker Image...'
|
||||
script {
|
||||
def dockerRepo = BRANCH_NAME == 'main' ? DOCKERHUB_REPO_MAIN : DOCKERHUB_REPO_MR
|
||||
def imageTag = "${DOCKERHUB_USER}/${dockerRepo}:${GIT_COMMIT_SHORT}"
|
||||
|
||||
withCredentials([usernamePassword(credentialsId: DOCKER_CREDENTIALS_ID, usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) {
|
||||
withCredentials([usernamePassword(credentialsId: "${DOCKER_CREDENTIALS_ID}", usernameVariable: 'DOCKER_USERNAME', passwordVariable: 'DOCKER_PASSWORD')]) {
|
||||
sh """
|
||||
echo "$PASSWORD" | docker login -u "$USERNAME" --password-stdin
|
||||
docker build -t ${imageTag} .
|
||||
docker push ${imageTag}
|
||||
docker logout
|
||||
echo $DOCKER_PASSWORD | docker login -u $DOCKER_USERNAME --password-stdin
|
||||
docker build -t marijastopa/mr-jenkins:\${GIT_COMMIT:0:7} .
|
||||
docker push marijastopa/mr-jenkins:\${GIT_COMMIT:0:7}
|
||||
"""
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue