Update Jenkinsfile

This commit is contained in:
lwj9812 2024-03-22 12:07:53 +09:00 committed by GitHub
parent a332ddf09d
commit 72cd1612fa
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

49
Jenkinsfile vendored
View file

@ -5,6 +5,15 @@ pipeline {
maven "M3"
}
environment {
AWS_CREDENTIAL_NAME = "AWSCredentials"pipeline {
agent any
tools {
jdk "jdk17"
maven "M3"
}
environment {
AWS_CREDENTIAL_NAME = "AWSCredentials"
REGION = "ap-northeast-2"
@ -14,37 +23,33 @@ pipeline {
}
stages {
stage('Git clone') {
stage('Git Clone') {
steps {
echo 'Git clone'
echo 'Git Clone'
git url: 'https://github.com/lwj9812/spring-petclinic.git',
branch: 'efficient-webjars'
}
post {
success {
echo 'Git Clone Success!!'
echo 'success clone project'
}
failure {
echo 'Git Clone Fail'
error 'fail clone project' // exit pipeline
}
}
}
stage('Maven Build') {
stage ('mvn Build') {
steps {
echo 'Maven Build'
sh 'mvn -Dmaven.test.failure.ignore=true clean package'
sh 'mvn -Dmaven.test.failure.ignore=true install'
}
post {
success {
junit 'target/surefire-reports/**/*.xml'
junit '**/target/surefire-reports/TEST-*.xml'
}
}
}
stage ('Docker Image Build') {
stage ('Docker Build') {
steps {
echo 'Docker Image Build'
dir("${env.WORKSPACE}") {
sh """
docker build -t $ECR_DOCKER_IMAGE:$BUILD_NUMBER .
@ -53,24 +58,29 @@ pipeline {
}
}
}
stage ('Push Docker Image to ECR') {
stage('Push Docker Image') {
steps {
echo "Push Docker Image to ECR"
script{
// cleanup current user docker credentials
sh 'rm -f ~/.dockercfg ~/.docker/config.json || true'
docker.withRegistry("http://${ECR_REPOSITORY}", "ecr:${REGION}:${AWS_CREDENTIAL_NAME}") {
docker.withRegistry("https://${ECR_REPOSITORY}", "ecr:${REGION}:${AWS_CREDENTIAL_NAME}") {
docker.image("${ECR_DOCKER_IMAGE}:${BUILD_NUMBER}").push()
docker.image("${ECR_DOCKER_IMAGE}:latest").push()
}
}
}
}
}
}
post {
success {
echo "Push Docker Image success!"
}
}
}
stage('Clean Up Docker Images on Jenkins Server') {
steps {
echo 'Cleaning up unused Docker images on Jenkins server'
sh "docker image prune -a -f"
sh "docker image prune -f -a"
}
}
stage('Upload to S3') {
@ -86,5 +96,6 @@ pipeline {
}
}
}
}