forked from ramnadh333/sample-app-1
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathjenkinsfile-7pm
More file actions
executable file
·63 lines (62 loc) · 2.99 KB
/
jenkinsfile-7pm
File metadata and controls
executable file
·63 lines (62 loc) · 2.99 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
node {
stage('SourceCodeFromGit') {
git credentialsId: 'GitCredentials', url: 'https://github.com/devops-mptech/sample-app.git'
}
f = sh (
script: 'sh projectversion.sh',
returnStdout: true
).trim()
stage('MavenBuildWithoutTestCases') {
def Maven_Home = tool name: 'Maven-3.3.9', type: 'maven'
def Maven_Bin = "${Maven_Home}/bin"
sh "${Maven_Bin}/mvn clean package -DskipTests"
}
stage('MavenBuild') {
def Maven_Home = tool name: 'Maven-3.3.9', type: 'maven'
def Maven_Bin = "${Maven_Home}/bin"
sh "${Maven_Bin}/mvn clean package"
}
stage('DockerImageBuild') {
sh "docker build -t devopsmptech/tomcat11:${f} ."
}
stage('Sending Email') {
mail bcc: '', body: 'Sampleapp app successfully builded', cc: '', from: '', replyTo: '', subject: 'Sampleapp', to: 'sureshbabu.alns@gmail.com'
}
stage('PushDockerImageToDockerHub') {
withCredentials([string(credentialsId: 'DockerHubPassword1', variable: 'DockerHubPassword1')]) {
sh "docker login -u devopsmptech -p ${DockerHubPassword1}"
sh "docker push devopsmptech/tomcat11:${f}"
}
}
stage('RunDockerContaionerDev') {
sshagent(['ec2-userKey']) {
def Docker_Command3 = "docker rm -f suresh"
def Docker_Command4 = "docker rm -f suresh1"
def Docker_Command5 = "docker rmi -f devopsmptech/tomcat11:${f}"
def Docker_Command1 = "docker run -d -p 8080:8080 --name suresh devopsmptech/tomcat11:${f}"
def Docker_Command2 = "docker run -d -p 9090:8080 --name suresh1 devopsmptech/tomcat11:${f}"
sh "ssh -o StrictHostKeyChecking=no ec2-user@172.31.23.159 ${Docker_Command5}"
sh "ssh -o StrictHostKeyChecking=no ec2-user@172.31.23.159 ${Docker_Command3}"
sh "ssh -o StrictHostKeyChecking=no ec2-user@172.31.23.159 ${Docker_Command4}"
sh "ssh -o StrictHostKeyChecking=no ec2-user@172.31.23.159 ${Docker_Command1}"
sh "ssh -o StrictHostKeyChecking=no ec2-user@172.31.23.159 ${Docker_Command2}"
}
}
stage('RunDockerContaionerProud') {
sshagent(['ec2-userKey']) {
def Docker_Command6 = "docker rm -f suresh"
def Docker_Command7 = "docker rm -f suresh1"
def Docker_Command8 = "docker rmi -f devopsmptech/tomcat11:${f}"
def Docker_Command9 = "docker run -d -p 8080:8080 --name suresh devopsmptech/tomcat11:${f}"
def Docker_Command10 = "docker run -d -p 9090:8080 --name suresh1 devopsmptech/tomcat11:${f}"
sh "ssh -o StrictHostKeyChecking=no ec2-user@172.31.19.253 ${Docker_Command6}"
sh "ssh -o StrictHostKeyChecking=no ec2-user@172.31.19.253 ${Docker_Command7}"
sh "ssh -o StrictHostKeyChecking=no ec2-user@172.31.19.253 ${Docker_Command8}"
sh "ssh -o StrictHostKeyChecking=no ec2-user@172.31.19.253 ${Docker_Command9}"
sh "ssh -o StrictHostKeyChecking=no ec2-user@172.31.19.253 ${Docker_Command10}"
}
}
stage('Sending Mail') {
mail bcc: '', body: 'Sampleapp war successfully deployed', cc: '', from: '', replyTo: '', subject: 'Sampleapp', to: 'sureshbabu.alns@gmail.com'
}
}