-
Notifications
You must be signed in to change notification settings - Fork 105
Expand file tree
/
Copy pathJenkinsfile
More file actions
64 lines (52 loc) · 2.24 KB
/
Jenkinsfile
File metadata and controls
64 lines (52 loc) · 2.24 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
node{
def mavenHome, mavenCMD, docker, tag, dockerHubUser, containerName, httpPort = ""
stage('Prepare Environment'){
echo 'Initialize Environment'
mavenHome = tool name: 'maven' , type: 'maven'
mavenCMD = "${mavenHome}/bin/mvn"
tag="3.0"
dockerHubUser="anujsharma1990"
containerName="insure-me"
httpPort="8081"
}
stage('Code Checkout'){
try{
checkout scm
}
catch(Exception e){
echo 'Exception occured in Git Code Checkout Stage'
currentBuild.result = "FAILURE"
//emailext body: '''Dear All,
//The Jenkins job ${JOB_NAME} has been failed. Request you to please have a look at it immediately by clicking on the below link.
//${BUILD_URL}''', subject: 'Job ${JOB_NAME} ${BUILD_NUMBER} is failed', to: 'jenkins@gmail.com'
}
}
stage('Maven Build'){
sh "${mavenCMD} clean package"
}
stage('Publish Test Reports'){
publishHTML([allowMissing: false, alwaysLinkToLastBuild: false, keepAll: false, reportDir: 'target/surefire-reports', reportFiles: 'index.html', reportName: 'HTML Report', reportTitles: '', useWrapperFileDirectly: true])
}
stage('Docker Image Build'){
echo 'Creating Docker image'
sh "docker build -t $dockerHubUser/$containerName:$tag --pull --no-cache ."
}
stage('Docker Image Scan'){
echo 'Scanning Docker image for vulnerbilities'
sh "docker build -t ${dockerHubUser}/insure-me:${tag} ."
}
stage('Publishing Image to DockerHub'){
echo 'Pushing the docker image to DockerHub'
withCredentials([usernamePassword(credentialsId: 'dockerHubAccount', usernameVariable: 'dockerUser', passwordVariable: 'dockerPassword')]) {
sh "docker login -u $dockerUser -p $dockerPassword"
sh "docker push $dockerUser/$containerName:$tag"
echo "Image push complete"
}
}
stage('Docker Container Deployment'){
sh "docker rm $containerName -f"
sh "docker pull $dockerHubUser/$containerName:$tag"
sh "docker run -d --rm -p $httpPort:$httpPort --name $containerName $dockerHubUser/$containerName:$tag"
echo "Application started on port: ${httpPort} (http)"
}
}