diff --git a/jenkinsfile b/jenkinsfile new file mode 100644 index 0000000..c3c0f02 --- /dev/null +++ b/jenkinsfile @@ -0,0 +1,55 @@ +pipeline { + agent any + + environment { + AWS_ACCOUNT_ID = "646347823701" + AWS_DEFAULT_REGION = "ap-south-1" + IMAGE_REPO_NAME = "jenkins-pipeline-demo" + IMAGE_TAG = "latest" + REPO_URL = "${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_DEFAULT_REGION}.amazonaws.com/${IMAGE_REPO_NAME}" + } + + stages { + stage('Git Checkout') { + steps { + git branch: 'main', url: 'https://github.com/bhagyashree3235/java-example.git' + } + } + + stage('dockerbuild') { + steps { + script { + sh "docker build -t ${REPO_URL}:${IMAGE_TAG} ." + } + } + } + + stage('Logging to AWS ECR') { + steps { + script { + sh """aws ecr get-login-password \ + --region ap-south-1 \ + | docker login \ + --username AWS \ + --password-stdin 646347823701.dkr.ecr.ap-south-1.amazonaws.com""" + } + } + } + + stage('ECR push') { + steps { + script { + sh """docker push ${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_DEFAULT_REGION}.amazonaws.com/${IMAGE_REPO_NAME}:${IMAGE_TAG}""" + } + } + } + + stage('Deploy to Docker Server') { + steps { + script { + sh "docker run -d -p 8080:8080 ${REPO_URL}:${IMAGE_TAG}" + } + } + } + } +}