forked from sudheer76R/java-example
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjen
More file actions
82 lines (78 loc) · 2.45 KB
/
jen
File metadata and controls
82 lines (78 loc) · 2.45 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
pipeline {
agent any
tools {
jdk 'JDK17'
maven 'Maven3'
}
environment {
REPOSITORY_URI = "515966525347.dkr.ecr.ap-south-1.amazonaws.com/assignment"
DOCKER_IMAGE = "shrikant712/docker:latest"
SCANNER_HOME= tool 'sonar-scanner'
}
stages {
stage('Checkout Source Code') {
steps {
git branch: 'main', changelog: false, poll: false, url: 'https://github.com/Madhav0987/java-example.git'
}
}
stage('building artifact'){
steps{
sh 'mvn claean install'
}
}
stage('unit tests'){
steps{
sh 'mvn test'
}
}
stage('sonarqube'){
steps{
withSonarQubeEnv('Sonar-server') {
sh ''' $SCANNER_HOME/bin/sonar-scanner -Dsonar.url=http://52.66.213.248:9000/ -Dsonar.projectName="Java WebApp" \
-Dsonar.java.binaries=. \
-Dsonar.projectKey=Java-WebApp '''
}
}
}
stage('Build Docker Image') {
steps {
sh """
docker build -t ubuntu:v1 .
"""
}
}
stage('Push to DockerHub') {
steps {
script {
withCredentials([string(credentialsId: 'Dockerhub-password', variable: 'Dockerhub')]) {
sh 'docker login -u shrikant712 -p ${Dockerhub}'
}
sh 'docker tag ubuntu:v1 ${DOCKER_IMAGE}'
sh 'docker push ${DOCKER_IMAGE}'
}
}
}
stage('Push to AWS ECR') {
steps {
script {
withEnv(["AWS_ACCESS_KEY_ID=${env.AWS_ACCESS_KEY_ID}", "AWS_SECRET_ACCESS_KEY=${env.AWS_SECRET_ACCESS_KEY}", "AWS_DEFAULT_REGION=${env.AWS_DEFAULT_REGION}"])
{
sh """
aws ecr get-login-password --region ap-south-1 | \
docker login --username AWS --password-stdin 515966525347.dkr.ecr.ap-south-1.amazonaws.com
docker tag ubuntu:v1 ${REPOSITORY_URI}:v1
docker push ${REPOSITORY_URI}:v1
"""
}
}
}
}
stage('Docker Run'){
steps{
script{
sh 'docker run -it -d ubuntu:v1'
}
}
}
}
}