-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile
More file actions
161 lines (134 loc) · 5.09 KB
/
Jenkinsfile
File metadata and controls
161 lines (134 loc) · 5.09 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
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
pipeline
{
agent any
stages {
stage("Clean workspace")
{
steps
{
sh "echo Cleaning up workspace..."
cleanWs()
}
}
stage("Get latest source")
{
steps
{
withCredentials([string(credentialsId: 'btoken', variable: 'TOKEN')]) {
sh "/home/jenkins/bitbucketnotifier.sh INPROGRESS ${commit} ${commit} ${TOKEN} ${BUILD_NUMBER}"
}
git branch: '${pushed_branch}', credentialsId: 'JenkinsSSH', url: 'ssh://git@tools.uia.no:7999/ikt201g22h/lootefix.git'
echo 'Pulling from git...'
echo 'Checking out the commit'
sh "git checkout ${commit}"
}
}
stage("Build main image")
{
steps
{
script
{
try
{
sh "docker build -f Dockerfile . -t lootefix:test"
}
catch(Exception e)
{
sh "echo Build of main image failed"
currentBuild.result = 'ABORTED'
withCredentials([string(credentialsId: 'btoken', variable: 'TOKEN')]) {
sh "/home/jenkins/bitbucketnotifier.sh FAILED ${commit} ${commit} ${TOKEN} ${BUILD_NUMBER}"
}
// Something failed, abort the pipeline
error("Failed to build main image")
}
}
}
}
stage("Create and start main container")
{
steps
{
script
{
try
{
sh "docker stop lootefixtest || true && docker rm lootefixtest || true"
sh "docker create -p 7268:80 --name lootefixtest lootefix:test"
sh "docker start lootefixtest"
}
catch(Exception e)
{
sh "echo Failed to start main container"
currentBuild.result = 'ABORTED'
withCredentials([string(credentialsId: 'btoken', variable: 'TOKEN')]) {
sh "/home/jenkins/bitbucketnotifier.sh FAILED ${commit} ${commit} ${TOKEN} ${BUILD_NUMBER}"
}
// Something failed, abort the pipeline
error("Failed to start main container")
}
}
}
}
stage("Build test container")
{
steps
{
script
{
try
{
sh "docker build -t lootefix_xunit -f Dockerfile.xunit ."
}
catch(Exception e)
{
sh "echo Building xunit image failed"
withCredentials([string(credentialsId: 'btoken', variable: 'TOKEN')]) {
sh "/home/jenkins/bitbucketnotifier.sh FAILED ${commit} ${commit} ${TOKEN} ${BUILD_NUMBER}"
}
// Something failed, abort the pipeline
error("Building xunit image failed")
}
}
}
}
stage ("Run tests")
{
steps
{
sh "echo Running tests..."
script
{
// If tests succeed, update the build status to SUCCESSFUL on Bitbucket.
try
{
sh "docker stop xunit || true && docker rm xunit || true"
sh "docker run --tty --name xunit --rm --network host lootefix_xunit:latest | grep \"Connection refused\" > /dev/null"
sh "echo Tests successful"
withCredentials([string(credentialsId: 'btoken', variable: 'TOKEN')]) {
sh "/home/jenkins/bitbucketnotifier.sh SUCCESSFUL ${commit} ${commit} ${TOKEN} ${BUILD_NUMBER}"}
currentBuild.result = 'PASSED'
}
// If tests fail, update the build status to FAILED on Bitbucket.
catch (Exception e)
{
sh "echo Tests failed..."
buildresult: 'PASSED'
withCredentials([string(credentialsId: 'btoken', variable: 'TOKEN')]) {
sh "/home/jenkins/bitbucketnotifier.sh FAILED ${commit} ${commit} ${TOKEN} ${BUILD_NUMBER}"
}
error("Tests failed")
}
}
}
}
stage("Done!")
{
steps
{
sh "echo Done!"
}
}
}
}