-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathJenkinsfile
79 lines (68 loc) · 2.97 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
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
try{
node{
def mavenHome
def mavenCMD
def docker
def dockerCMD
def tagName = "1.0"
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://www.github.com/shubhamkushwah123/bootcamp10.git'
}
stage('Build, Test and Package'){
echo "Building the addressbook application..."
sh "${mavenCMD} clean package"
}
stage('Sonar Scan'){
echo "Scanning application for vulnerabilities..."
//sh "${mavenCMD} sonar:sonar -Dsonar.host.url=http://xx.xxx.xx.xx:9000"
}
stage('Integration test'){
echo "Executing Regression Test Suits..."
// command to execute selenium test suits
}
stage('publish report'){
echo " Publishing HTML report.."
publishHTML([allowMissing: false, alwaysLinkToLastBuild: false, keepAll: false, reportDir: '', reportFiles: 'index.html', reportName: 'HTML Report', reportTitles: ''])
}
stage('Build Docker Image'){
echo "Building docker image for addressbook application ..."
sh "${dockerCMD} build -t shubhamkushwah123/addressbook:${tagName} ."
}
stage("Push Docker Image to Docker Registry"){
echo "Pushing image to docker hub"
withCredentials([string(credentialsId: 'dockerPwd', variable: 'dockerHubPwd')]) {
sh "${dockerCMD} login -u shubhamkushwah123 -p ${dockerHubPwd}"
sh "${dockerCMD} push shubhamkushwah123/addressbook:${tagName}"
}
}
stage('Deploy Application'){
echo "Installing desired software.."
echo "Bring docker service up and running"
echo "Deploying addressbook application"
ansiblePlaybook credentialsId: 'ssh', disableHostKeyChecking: true, installation: 'ansible 2.9.22', inventory: '/etc/ansible/hosts', playbook: 'deploy-playbook.yml'
}
stage('Clean up'){
echo "Cleaning up the workspace..."
cleanWs()
}
}
}
catch(Exception err){
echo "Exception occured..."
currentBuild.result="FAILURE"
//send an failure email notification to the user.
}
finally {
(currentBuild.result!= "ABORTED") && node("master") {
echo "finally gets executed and end an email notification for every build"
//emailext body: 'Your build has been successful or unsuccessful', subject: 'Build Result', to: '[email protected]'
}
}