-
Notifications
You must be signed in to change notification settings - Fork 47
/
Master-Slave-Notes
231 lines (127 loc) · 4.19 KB
/
Master-Slave-Notes
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
************************************
Master and slave set up:
1. Master machine and change the Jenkisn URL in Jenkins configure system section
Manage Jenkins --> configure system --> scroll down --> Jenkins Location-->give the latest Jenkins URL ==> save it
update the latest URL over there
2. For master and slave to communicate , you will need Agent port
By default it is disabled in jenkins. You need to enable it
Manage Jenkins --> Configure global security --> scroll down to Agent section ==> select random ==> save it
Slave set up:
***********************
Install the following tools:
Git installation:
yum install git -y
JAVA Installation
yum install java-1.8.0-openjdk-devel
Maven Installation:
***************
yum install maven -y
Create the root directory/workspace on the slave for master to place the rmeote files and output files
*******************************
cd /tmp
mkdir jenkinsdir
We need to give permission to this directory, so that master can read and write int this directory
chmod -R 777 /tmp/jenkinsdir
This is the path of directory
/tmp/jenkinsdir
******************************************
Connect Master to the Slave
*****************************************
Manage jenkins--> Manage nodes & clouds --> on left side click on New node
Give name as Jnekinsslave --> select permanent agent --> click on create
Name: already populated
Description: Slave is of Lunix OS
Number of executors: 1
here executors means, jobs that can be executed on the slave at a time
Remote root directory: /tmp/jenkinsdir
Label: jenkinsSlave
Usage: Only build jobs with label expression matching this node
Launch method:
how do you want to connect slave to master
1. Launch method : select==> launch agents via ssh
Host : private ip address of slave
Credentials:
Click on Add button --> click on jenkins button
Kind: SSH username with private key
id: jenkisnslave
description: slave credentials
Username: ec2-user
Private Key : click on Enter directly ==> click on add button
Open the pem file of slave server using notepad in your downloads folder
and copy all the contents ==> CTL A + CTL C
and paste it under private key step
Click on add button
In credentials drop down select the credentials
Host Key Verification Strategy
> select Non verifying verification strategy
Availability : keep this node online as much as psosible
Tool location
********************
Location of tool git and java on the slave
git : /usr/bin/git
java: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.332.b09-1.amzn2.0.2.x86_64
Dispatching the jobs to slave & master:
********************
pipeline{
tools{
jdk 'myjava'
maven 'mymaven'
}
agent none
stages{
stage('Clone repo')
{
agent {label 'jenkinsSlave'}
steps{
git 'https://github.com/Sonal0409/DevOpsCodeDemo.git'
}
}
stage('Compile the code')
{
agent any
steps{
git 'https://github.com/Sonal0409/DevOpsCodeDemo.git'
sh 'mvn compile'
}
}
stage('Code Review')
{
agent any
steps{
sh 'mvn pmd:pmd'
}
}
stage('test the code')
{
agent {label 'jenkinsSlave'}
steps{
echo 'Testing'
sh 'mvn test'
}
post{
success{
junit 'target/surefire-reports/*.xml'
}
}
}
stage('Coverage of the code')
{
agent {label 'jenkinsSlave'}
steps{
sh 'mvn cobertura:cobertura -Dcobertura.report.format=xml'
}
post{
success{
cobertura autoUpdateHealth: false, autoUpdateStability: false, coberturaReportFile: 'target/site/cobertura/coverage.xml', conditionalCoverageTargets: '70, 0, 0', failUnhealthy: false, failUnstable: false, lineCoverageTargets: '80, 0, 0', maxNumberOfBuilds: 0, methodCoverageTargets: '80, 0, 0', onlyStable: false, sourceEncoding: 'ASCII', zoomCoverageChart: false
}
}
}
stage('Package the code')
{
agent {label 'jenkinsSlave'}
steps{
sh 'mvn package'
}
}
}
}