forked from sudheer76R/java-example
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathjenkins_docker_new
More file actions
38 lines (38 loc) · 1.35 KB
/
jenkins_docker_new
File metadata and controls
38 lines (38 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
pipeline{
agent {label 'docker_node_new'}
environment {
AWS_ACCOUNT_ID="905418352029"
AWS_DEFAULT_REGION="ap-south-1"
IMAGE_REPO_NAME="fatimatabassum"
}
stages{
stage('Checkout'){
steps{
git branch: 'main' , url: 'https://github.com/fatimatabassum05/java-example'
}
}
stage('Build Docker Image'){
steps{
script{
sh '''
echo 'Build docker image'
docker build -t ${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_DEFAULT_REGION}.amazonaws.com/${IMAGE_REPO_NAME}:${BUILD_NUMBER} .
'''
}
}
}
stage('Push to ECR'){
steps{
script {
sh 'aws ecr get-login-password --region ${AWS_DEFAULT_REGION} | docker login --username AWS --password-stdin ${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_DEFAULT_REGION}.amazonaws.com'
sh 'docker push ${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_DEFAULT_REGION}.amazonaws.com/${IMAGE_REPO_NAME}:${BUILD_NUMBER}'
}
}
}
stage('Deploy the container'){
steps{
sh 'docker run -itd -p 9010:8080 ${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_DEFAULT_REGION}.amazonaws.com/${IMAGE_REPO_NAME}:${BUILD_NUMBER}'
}
}
}
}