forked from challadevops1/InsureMe-03May
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
65 lines (50 loc) · 2.38 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
node{
def mavenHome
def mavenCMD
def docker
def dockerCMD
def tagName
stage('prepare enviroment'){
echo 'initialize all the variables'
mavenHome = tool name: 'maven' , type: 'maven'
mavenCMD = "${mavenHome}/bin/mvn"
docker = tool name: 'docker' , type: 'org.jenkinsci.plugins.docker.commons.tools.DockerTool'
dockerCMD = "${docker}/bin/docker"
tagName="3.0"
}
stage('git code checkout'){
try{
echo 'checkout the code from git repository'
git 'https://github.com/shubhamkushwah123/star-agile-insurance-project.git'
}
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: 'shubham@gmail.com'
}
}
stage('Build the Application'){
echo "Cleaning... Compiling...Testing... Packaging..."
//sh 'mvn clean package'
sh "${mavenCMD} clean package"
}
stage('publish test reports'){
publishHTML([allowMissing: false, alwaysLinkToLastBuild: false, keepAll: false, reportDir: '/var/lib/jenkins/workspace/Capstone-Project-Live-Demo/target/surefire-reports', reportFiles: 'index.html', reportName: 'HTML Report', reportTitles: '', useWrapperFileDirectly: true])
}
stage('Containerize the application'){
echo 'Creating Docker image'
sh "${dockerCMD} build -t shubhamkushwah123/insure-me:${tagName} ."
}
stage('Pushing it ot the DockerHub'){
echo 'Pushing the docker image to DockerHub'
withCredentials([string(credentialsId: 'dock-password', variable: 'dockerHubPassword')]) {
sh "${dockerCMD} login -u shubhamkushwah123 -p ${dockerHubPassword}"
sh "${dockerCMD} push shubhamkushwah123/insure-me:${tagName}"
}
stage('Configure and Deploy to the test-server'){
ansiblePlaybook become: true, credentialsId: 'ansible-key', disableHostKeyChecking: true, installation: 'ansible', inventory: '/etc/ansible/hosts', playbook: 'ansible-playbook.yml'
}
}
}