-
Notifications
You must be signed in to change notification settings - Fork 9
/
Jenkinsfile
84 lines (77 loc) · 3.42 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
@Library('swarm-deploy') _
def DockerApp
node ('Docker') {
stage ('Checkout') {
checkout scm
}
stage ('Pull Dyalog Container') {
withDockerRegistry(credentialsId: '0435817a-5f0f-47e1-9dcc-800d85e5c335') {
sh ('docker pull dyalog/dyalog')
}
}
stage ('Build Docker Image') {
withDockerRegistry(credentialsId: '0435817a-5f0f-47e1-9dcc-800d85e5c335') {
// Create a version file to include in the container
sh 'echo "$(cat version).$(git rev-list HEAD --count) - ($(git rev-parse HEAD))" > ./MiServer.version'
if (env.BRANCH_NAME.contains('master')) {
DockerApp = docker.build 'dyalog/miserver:latest'
} else {
DockerApp = docker.build "dyalog/miserver:${env.BRANCH_NAME}"
}
}
}
stage ('Test website') {
withDockerRegistry(credentialsId: '0435817a-5f0f-47e1-9dcc-800d85e5c335') {
def MiServer = DockerApp.run ('-t -e VIRTUAL_HOST=miserver.dyalog.bramley -e VIRTUAL_PORT=8080')
try {
//Get the IP of the container
def DOCKER_IP = sh (
script: "docker inspect ${MiServer.id} | jq .[0].NetworkSettings.IPAddress | sed 's/\"//g'",
returnStdout: true
).trim()
sh "rm -f /tmp/miserver-test.log"
sh "sleep 10 && for F in `ls ${WORKSPACE}/CI/test-*.sh`; do /bin/bash \${F} ${DOCKER_IP}; done"
MiServer.stop()
stash includes: 'service.yml', name: 'swarm-stash'
} catch (Exception e) {
println 'MiServer Not running correctly; cleaning up.'
sh "git rev-parse --short HEAD > .git/commit-id"
withCredentials([string(credentialsId: '250bdc45-ee69-451a-8783-30701df16935', variable: 'GHTOKEN')]) {
commit_id = readFile('.git/commit-id')
sh "${WORKSPACE}/CI/GH-Comment.sh ${MiServer.id} ${commit_id}"
}
MiServer.stop()
sh "docker rmi dyalog/miserver:latest"
throw e;
}
}
}
stage ('Publish Docker image') {
withDockerRegistry(credentialsId: '0435817a-5f0f-47e1-9dcc-800d85e5c335') {
if (env.BRANCH_NAME.contains('master')) {
DockerApp.push();
}
}
}
stage ('Cleanup') {
if (env.BRANCH_NAME.contains('master')) {
sh 'docker rmi dyalog/miserver:latest'
} else {
sh "docker rmi dyalog/miserver:${env.BRANCH_NAME}"
}
}
stage ('Github Upload') {
withCredentials([string(credentialsId: '250bdc45-ee69-451a-8783-30701df16935', variable: 'GHTOKEN')]) {
sh './CI/GH-Release.sh'
}
}
}
if (env.BRANCH_NAME.contains('master')) {
node (label: 'swarm && gosport') {
stage('Deploying with Docker Swarm') {
unstash 'swarm-stash'
r = swarm "MiServer"
echo r
}
}
}