forked from tarun3834/batch11
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
51 lines (45 loc) · 1.82 KB
/
Jenkinsfile
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
try{
node{
def mavenHome
def mavenCMD
def docker
def dockerCMD
def tagName = "1.4"
stage('Preparation'){
echo "Preparing the Jenkins environment with required tools..."
mavenHome = tool name: 'maven 3', type: 'maven'
mavenCMD = "${mavenHome}/bin/mvn"
docker = tool name: 'docker', type: 'org.jenkinsci.plugins.docker.commons.tools.DockerTool'
//dockerCMD = "$docker/bin/docker"
}
stage('git checkout'){
echo "Checking out the code from git repository."
git 'https://github.com/tarun3834/batch10.git'
}
stage('Build, Test and Package'){
echo "Building the springboot application."
sh "${mavenCMD} clean package"
//sh "java -jar target/my-test-app*.jar"
}
stage('Sonar check'){
echo "scanning the app"
tool name:'maven 3',type: 'maven'
sh 'mvn sonar:sonar -Dsonar.projectKey=sonar -Dsonar.login=admin -Dsonar.password=admin123 -Dsonar.sources=/var/lib/jenkins/workspace/case -Dsonar.host.url=http://34.69.89.128:9000'
}
stage('Build Docker Image'){
echo "Building docker image for springboot application."
sh "docker build -t tarun3834/spring:${tagName} ."
}
stage("Push Docker Image to Docker Registry"){
echo "Pushing image to docker hub"
withCredentials([string(credentialsId: 'dockerPwd', variable: 'dockerHubPwd')]) {
sh "docker login -u tarun3834 -p ${dockerHubPwd}"
}
sh "docker push tarun3834/spring:${tagName}"
}
}
}
catch(Exception err){
}
finally{
}