Update Jenkinsfile

This commit is contained in:
lwj9812 2024-03-15 15:34:46 +09:00 committed by GitHub
parent a200b45770
commit 7eb1014e7e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

53
Jenkinsfile vendored
View file

@ -7,7 +7,7 @@ pipeline {
environment { environment {
AWS_CREDENTIAL_NAME = "AWSCredentials" AWS_CREDENTIAL_NAME = "AWSCredentials"
REGION = "ap-northest-2" REGION = "ap-northeast-2"
DOCKER_IMAGE_NAME = "std01-spring-petclinic" DOCKER_IMAGE_NAME = "std01-spring-petclinic"
ECR_REPOSITORY = "257307634175.dkr.ecr.ap-northeast-2.amazonaws.com" ECR_REPOSITORY = "257307634175.dkr.ecr.ap-northeast-2.amazonaws.com"
ECR_DOCKER_IMAGE = "${ECR_REPOSITORY}/${DOCKER_IMAGE_NAME}" ECR_DOCKER_IMAGE = "${ECR_REPOSITORY}/${DOCKER_IMAGE_NAME}"
@ -20,62 +20,67 @@ pipeline {
git url: 'https://github.com/lwj9812/spring-petclinic.git', git url: 'https://github.com/lwj9812/spring-petclinic.git',
branch: 'efficient-webjars' branch: 'efficient-webjars'
} }
post { post {
success { success {
echo 'Git Clone Success!!' echo 'Git Clone Success!!'
} }
failure { failure {
echo 'Git Clone Fail' echo 'Git Clone Fail'
}
} }
} }
}
stage('Mvnen Build') { stage('Maven Build') {
steps { steps {
echo 'Maven Build' echo 'Maven Build'
sh 'mvn -Dmaven.test.failure.igmore=ture clean package' sh 'mvn -Dmaven.test.failure.ignore=true clean package'
} }
post { post {
success { success {
junit 'target/surefire-reports/**/*.xml' junit 'target/surefire-reports/**/*.xml'
} }
} }
} }
stage ('Docker Image Build'){ stage ('Docker Image Build') {
steps { steps {
echo 'Docker Image Build' echo 'Docker Image Build'
dir("${env.WORKSPACE}") { dir("${env.WORKSPACE}") {
sh """ sh """
docker build -t $ECR_DOCKER_IMAGE:$BUILD_NUMBER . docker build -t $ECR_DOCKER_IMAGE:$BUILD_NUMBER .
docker tag $ECR_DOCKER_IMAGE:$BUILD_NUMBER $ECR_DOCKER_IMAGE:latest docker tag $ECR_DOCKER_IMAGE:$BUILD_NUMBER $ECR_DOCKER_IMAGE:latest
""" """
} }
} }
} }
stage ('Docker Image Build'){ stage ('Push Docker Image to ECR') {
steps { steps {
echo "Push Docker Image to ECR" echo "Push Docker Image to ECR"
script { script {
sh 'rm -f ~/.dockercfg~/.docker/config.json || true' sh 'rm -f ~/.dockercfg~/.docker/config.json || true'
docker.withRegistry("http://${ECR_REPOSITORY}", "ecr"${REGION}:${AWS_CREDENTIAL_NAME}") { docker.withRegistry("http://${ECR_REPOSITORY}", "ecr:${REGION}:${AWS_CREDENTIAL_NAME}") {
docker.image("${ECR_DOCKER_IMAGE}:latest").push() docker.image("${ECR_DOCKER_IMAGE}:latest").push()
}
} }
} }
} }
stage('Clean Up Docker Images on Jenkins Server'){ stage('Clean Up Docker Images on Jenkins Server'){
steps { steps {
echo 'Cleaning up unused Docker images on Jenkins server' echo 'Cleaning up unused Docker images on Jenkins server'
sh "docker image prune -f --all --filter \"nutil=1h\"" sh "docker image prune -f --all --filter \"until=1h\""
} }
} }
stage('Upload to S3'){
stage('Upload to S3') {
} }
stage('Codedeploy Workload'){
stage('Codedeploy Workload') {
} }
} }
} }