forked from artisantek/docker-sample-java-webapp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile
More file actions
45 lines (39 loc) · 1.31 KB
/
Jenkinsfile
File metadata and controls
45 lines (39 loc) · 1.31 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
39
40
41
42
43
44
45
pipeline {
agent any
environment {
AWS_ACCOUNT_ID = '767397778787'
AWS_REGION = 'ap-south-1'
IMAGE_REPO_NAME = 'java-app1'
IMAGE_TAG = 'ver1'
ECR_REGISTRY = "767397778787.dkr.ecr.ap-south-1.amazonaws.com"
REPOSITORY_URI = "767397778787.dkr.ecr.ap-south-1.amazonaws.com/docker-img"
}
stages {
stage('Check Docker Access') {
steps {
sh 'docker version'
}
}
stage('Build Docker Image') {
steps {
sh 'docker build -t ${IMAGE_REPO_NAME}:${IMAGE_TAG} .'
}
}
stage('Push Docker Image to ECR') {
steps {
withCredentials([usernamePassword(credentialsId: 'aws-credentials', usernameVariable: 'AWS_ACCESS_KEY_ID', passwordVariable: 'AWS_SECRET_ACCESS_KEY')]) {
sh '''
aws ecr get-login-password --region $AWS_REGION | docker login --username AWS --password-stdin $ECR_REGISTRY
docker tag $IMAGE_REPO_NAME:$IMAGE_TAG $REPOSITORY_URI:$IMAGE_TAG
docker push $REPOSITORY_URI:$IMAGE_TAG
'''
}
}
}
stage('Deploy') {
steps {
sh 'docker run -d --name java-app-container1 -p 8081:8080 $REPOSITORY_URI:$IMAGE_TAG'
}
}
}
}