Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
pipeline {
agent any

environment {
DOCKER_IMAGE = "your-dockerhub-username/spring-boot-app"
DOCKER_TAG = "latest"
AWS_REGION = "us-east-1"
ECS_CLUSTER = "your-ecs-cluster"
ECS_SERVICE = "your-ecs-service"
}

stages {
stage('Checkout') {
steps {
git branch: 'main', url: 'https://github.com/in28minutes/spring-boot-examples.git'
}
}

stage('Build') {
steps {
sh 'mvn clean package -DskipTests'
}
}

stage('Test') {
steps {
sh 'mvn test'
}
}

stage('Docker Build & Push') {
steps {
script {
sh "docker build -t ${DOCKER_IMAGE}:${DOCKER_TAG} ."
sh "echo ${env.DOCKER_HUB_PASSWORD} | docker login -u ${env.DOCKER_HUB_USERNAME} --password-stdin"
sh "docker push ${DOCKER_IMAGE}:${DOCKER_TAG}"
}
}
}

stage('Deploy to ECS') {
steps {
script {
sh """
aws ecs update-service --cluster ${ECS_CLUSTER} --service ${ECS_SERVICE} --force-new-deployment --region ${AWS_REGION}
"""
}
}
}
}