-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
156 lines (145 loc) · 5.2 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
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
def push()
{
sh 'groovy push.groovy ${BUILD_NUMBER} ${WORKSPACE}'
}
def pull()
{
sh 'groovy pull.groovy ${BUILD_NUMBER} ${WORKSPACE}'
}
node ("${SLAVE}") {
def downGradle
def downJava
try {
stage('Clean workspace before build') {
step([$class: 'WsCleanup'])
}
}
catch(clean)
{ // ${currentBuild.fullDisplayName} show in message "Pavel Kislouski » mntlab-ci-pipeline #$BUILD_NUMBER"
emailext body: 'Attention! Fail on step \"Clean workspace before build\"', subject: "${currentBuild.fullDisplayName} FAIL CLEAN STEP", to: '[email protected]'
throw any
}
try {
stage('installation') { //download java & gradle with the same names as on the master
git url: 'https://github.com/MNT-Lab/mntlab-pipeline.git', branch: 'pkislouski'
downGradle = tool 'gradle4.6'
downJava = tool 'java8'
}
}
catch(installion)
{
emailext body: 'Attention! Fail on step \"installation\"', subject: "${currentBuild.fullDisplayName} FAIL INSTALLATION STEP", to: '[email protected]'
throw any
}
try {
stage('Build') {
sh "'${downGradle}/bin/gradle' build"
}
}
catch(build)
{
emailext body: 'Attention! Fail on step \"build\"', subject: "${currentBuild.fullDisplayName} FAIL BUILD STEP", to: '[email protected]'
throw any // throw any - stop pipeline if have a message
}
try {
stage ('Testing') { // running parallel tests, can see parallel tests with a blue ocean plugin
parallel (
cucumber: {
stage ('cucumber') {
sh "'${downGradle}/bin/gradle' cucumber"
}
},
jacoco: {
stage ('jacoco') {
sh "'${downGradle}/bin/gradle' jacocoTestReport"
}
},
unit: {
stage ('unit test') {
sh "'${downGradle}/bin/gradle' test"
}
}
)
}
}
catch(test)
{
emailext body: 'Attention! Fail on step \"testing\"', subject: "${currentBuild.fullDisplayName} FAIL TESTING STEP", to: '[email protected]'
throw any
}
try {
stage ('Starting child job') {
build job: 'MNTLAB-Pavel__Kislouski-child1-build-job', parameters: [[$class: 'StringParameterValue', name: 'BRANCH_NAME', value: 'pkislouski']], quietPeriod: 2
}
}
catch(child)
{
emailext body: 'Attention! Fail on step \"Starting child job\"', subject: "${currentBuild.fullDisplayName} FAIL CHILD JOB STEP", to: '[email protected]'
throw any
}
try {
stage ('Copy artifact from job') { // copy artifact with plugin
step ([$class: 'CopyArtifact',
projectName: 'MNTLAB-Pavel__Kislouski-child1-build-job']);
}
}
catch(copy)
{
emailext body: 'Attention! Fail on step \"Copy artifact from job\"', subject: "${currentBuild.fullDisplayName} FAIL COPY ARTIFACT STEP", to: '[email protected]'
throw any
}
try {
stage ('Unarchive & Archive') {
sh 'cp build/libs/mntlab-ci-pipeline.jar .'
sh 'tar -xvf child1-*.tar.gz'
sh 'tar -czf ${WORKSPACE}/pipeline-pkislouski-${BUILD_NUMBER}.tar.gz mntlab-ci-pipeline.jar jobs.groovy'
}
}
catch(archive)
{
emailext body: 'Attention! Fail on step \"Unarchive and Archive\"', subject: "${currentBuild.fullDisplayName} FAIL Unarchive and Archive", to: '[email protected]'
throw any
}
try {
stage ('push nexus') { // call function push
push()
}
}
catch (push)
{
emailext body: 'Attention! Fail on step \"PUSH\"', subject: "${currentBuild.fullDisplayName} FAIL PUSH STEP", to: '[email protected]'
throw any
}
try {
stage('Asking for manual approval'){
input 'Deploy'
}
}
catch (approval)
{
emailext body: 'Attention! Fail on step \"APPROVAL\"', subject: "${currentBuild.fullDisplayName} FAIL APPROVAL STEP", to: '[email protected]'
throw any
}
try {
stage ('pull from nexus') { // call function pull
pull()
}
}
catch (pull)
{
emailext body: 'Attention! Fail on step \"PULL\"', subject: "${currentBuild.fullDisplayName} FAIL PULL STEP", to: '[email protected]'
throw any
}
try {
stage ('Unarchive & Execute') {
sh 'tar -xvf nexus.tar.gz'
sh 'java -jar mntlab-ci-pipeline.jar'
emailext body: 'Attention! Deploy SUCCESS', subject: "${currentBuild.fullDisplayName} SUCCESS", to: '[email protected]'
}
}
catch (All)
{
emailext body: 'Attention! Fail on step \"Execute\"', subject: "${currentBuild.fullDisplayName} FAIL EXECUTE STEP", to: '[email protected]'
throw any
}
}