-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathJenkinsfile
37 lines (31 loc) · 970 Bytes
/
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
node('docker-slave-general') {
def DockerImage = "webserver:v1.0"
stage('Pre') { // Run pre-build steps
cleanWs()
sh "docker rm -f webserver || true"
}
stage('Git') { // Get code from GitLab repository
git branch: 'master',
url: 'https://github.com/ops-school/dummyExporter.git'
}
stage('Build') { // Run the docker build
sh "docker build --tag ${DockerImage} ."
}
stage('Run') { // Run the built image
sh "docker run -d --name webserver --rm -p 8081:5000 ${DockerImage}; sleep 5"
}
stage('Test') { // Run tests on container
def dockerOutput = sh (
script: 'curl http://172.17.0.1:8081/isUp',
returnStdout: true
).trim()
sh "docker rm -f webserver"
if ( dockerOutput == 'DUMMY EXPORTER IS UP!' ) {
currentBuild.result = 'SUCCESS'
} else {
currentBuild.result = 'FAILURE'
sh "echo Webserver returned ${dockerOutput}"
}
return
}
}