-
Notifications
You must be signed in to change notification settings - Fork 1
/
pipelinescript
77 lines (71 loc) · 2.85 KB
/
pipelinescript
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
def sendMail(mailto,from,mailsubject,content) {
mail bcc: '', body: content, cc: '', from: from, replyTo: '', subject: mailsubject, to: mailto
}
def is_test_done1 = false
def is_test_done2 = false
node {
try{
properties([buildDiscarder(logRotator(artifactDaysToKeepStr: '', artifactNumToKeepStr: '', daysToKeepStr: '10', numToKeepStr: '10'))])
stage('Testing') {
try{
parallel (
'A' : {
retry(1) {
try {
build 'TestWebMavenSlave1'
is_test_done1 = true
}
catch (error) {
// Mark branch as failed somewhere
sendMail('[email protected]','[email protected]','Job failed',error.getMessage())
is_test_done1 = false
}
}
},
'B' : {
retry(1) {
try {
build 'TestWebMavenSlave2'
is_test_done2 = true
}
catch (error) {
// Mark branch as failed somewhere
sendMail('[email protected]','[email protected]','Job failed',error.getMessage())
is_test_done2 = false
}
}
}
)
}catch (error) {
sendMail('[email protected]','[email protected]','Job failed',error.getMessage())
is_test_done1 = false
is_test_done2 = false
}
}
stage('Deployment') {
try{
if(is_test_done1 == true && is_test_done2 == true){
build "LaunchConfigureAWSInstance"
retry(2){
echo "putting on sleep mode"
sleep time: 10000, unit: 'MILLISECONDS'
echo "started"
def ip = sh(script:"aws ec2 describe-instances --filters 'Name=tag:Name,Values=tomcatwebserver' 'Name=instance-state-name,Values=running' --output text --query 'Reservations[*].Instances[*].PublicIpAddress'", returnStdout:true)
ip = "${ip}".trim()
def deployname = "pmf"
build job:"DeplyWebMasterJob", parameters: [[$class: 'StringParameterValue', name: 'PUBLICIP', value: "http://"+"${ip}:8080"],[$class: 'StringParameterValue', name: 'APPNAME', value: "${deployname}"]],wait: true
sendMail('[email protected]','[email protected]','Deployment done',"Deployment done at http://"+"${ip}:8080/"+"${deployname}")
}
}else{
throw new Exception("Deployment failed")
}
}catch (error) {
sendMail('[email protected]','[email protected]','Deployment failed',error.getMessage())
throw new Exception("Deployment failed")
}
}
}
catch (error) {
println (error)
}
}