-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile_Puppet
169 lines (166 loc) · 4.5 KB
/
Jenkinsfile_Puppet
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
def istoarchive = 'FALSE'
def needtorestore = 'FALSE'
def microsoftteamsrecipientwebhookurl = 'https://outlook.office.com/webhook/bec5e87a-b2b3-48c4-994f-75f450422293@3cd788f0-4406-4d04-afa9-b28bca6e0b21/JenkinsCI/4de75f08e14245fa9f825911c42c4460/9eab3e39-3de4-4dbc-999f-94520f178250'
pipeline
{
agent none
stages
{
stage('CheckOut and Build The Application')
{
agent { label 'master' }
steps
{
script
{
def mvn_version = 'maven_3_5_4'
withEnv( ["PATH+MAVEN=${tool mvn_version}/bin"] )
{
sh "mvn clean install"
}
}
}
post
{
success
{
echo 'Copying the war file and pushing to War Repo'
sh 'cp target/*.war /home/kovair/ApplicationWar/'
//'************ Pushing the war files to ssh://[email protected]:22/home/kovair/MyGitFiles/WarRepository.git ************'
sh '''
cd /home/kovair/ApplicationWar/
git pull origin master
git add .
git commit -m "War updated."
git push origin master
'''
}
failure
{
script
{
office365ConnectorSend message: "Build Failed", status: 'Failed', webhookUrl: '${microsoftteamsrecipientwebhookurl}'
}
}
}
}
stage('Deploy Application on Tomcat')
{
agent { label 'Tomcat Agent' }
steps
{
echo 'Starting deployment using Puppet'
sh 'set +e; puppet agent -t; if [ $? == 2 ]; then exit 0; fi'
}
post
{
success
{
script
{
office365ConnectorSend message: "Deployed successfully to Test server", status: 'Success', webhookUrl: '${microsoftteamsrecipientwebhookurl}'
}
}
}
}
stage('Test Application with Robot Framework')
{
agent { label 'testnode' }
steps
{
sleep(time:10,unit:"SECONDS")
echo 'Starting robot tests'
script
{
dir('RobotTests')
{
sh '''robot -v START_URL:http://192.168.11.175:8080/KovairDevOpsDemoApp_Puppet/ -d Results Tests/KovairDevOpsDemoApp.robot'''
}
step([$class: 'RobotPublisher',
disableArchiveOutput: false,
enableCache: true,
logFileName: 'log.html',
onlyCritical: true,
otherFiles: '',
outputFileName: 'output.xml',
outputPath: 'RobotTests/Results',
passThreshold: 100.0,
reportFileName: 'report.html',
unstableThreshold: 100.0])
}
}
post
{
success
{
script
{
istoarchive = 'TRUE'
needtorestore = 'FALSE'
}
}
failure
{
build('Revert Test Server to Last Stable Deployment')
script
{
office365ConnectorSend message: "Robot Tests failed for the application with Url: <a href='http://192.168.11.175:8080/KovairDevOpsDemoApp_Puppet/'>http://192.168.11.175:8080/KovairDevOpsDemoApp_Puppet/</a>", status: 'Failed', webhookUrl: '${microsoftteamsrecipientwebhookurl}'
}
}
}
}
stage('Archive Artifacts to Git Repository')
{
agent { label 'Tomcat Agent' }
when
{
beforeAgent true
expression
{
return istoarchive != 'FALSE';
}
}
steps
{
sh '''
cd /usr/share/tomcat/webapps
cp /usr/share/tomcat/webapps/KovairDevOpsDemoApp_Puppet.war /home/kovair/gitWarRepo/KovairDevOpsDemoApp_Puppet_stable.war
cd /home/kovair/gitWarRepo
git pull origin master
git add KovairDevOpsDemoApp_Puppet_stable.war
git commit -m "War archived to repository"
git push origin master
'''
}
post
{
success
{
script
{
office365ConnectorSend message: "War file archived successfully to Git", status: 'Success', webhookUrl: '${microsoftteamsrecipientwebhookurl}'
}
}
}
}
stage('Deploy and Run Application on Docker')
{
agent { label 'Docker Agent' }
steps
{
echo 'Starting Deployment on Docker using Puppet'
sh 'set +e; puppet agent -t; if [ $? == 2 ]; then exit 0; fi'
}
post
{
success
{
script
{
office365ConnectorSend message: "Application successfully deployed to Docker. Docker Url: <a href='http://192.168.11.109:9999/KovairDevOpsDemoApp_Puppet'>http://192.168.11.109:9999/KovairDevOpsDemoApp_Puppet/</a> ", status: 'Success', webhookUrl: '${microsoftteamsrecipientwebhookurl}'
}
}
}
}
}
}