-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
76 lines (61 loc) · 3.07 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
/* groovylint-disable CompileStatic, DuplicateStringLiteral, LineLength, NoDef, UnnecessaryGString, UnusedVariable, VariableTypeRequired */
pipeline {
options {
disableConcurrentBuilds()
}
agent any
stages {
stage('Build') {
steps {
slackSend (color: 'warning', message: "START: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' (${env.BUILD_URL})", channel: "#jenkins")
script {
def branchName = "${env.BRANCH_NAME}".toLowerCase().replaceAll("/", "_")
def dockerNet = "${branchName}-net"
def appImage = "${branchName}-app"
def testImage = "${branchName}-test"
sh "docker ps -a --filter name=${branchName} -q | xargs docker stop || true"
sh "docker ps -a --filter name=${branchName} -q | xargs docker rm || true"
sh "docker images --filter=reference='*${branchName}*:*' -q | xargs docker rmi || true"
sh "docker network ls --filter=name=${branchName}-* -q | xargs docker network rm || true"
sh "docker network create --driver bridge ${dockerNet}"
sh "docker build -t ${appImage} -f Dockerfile ."
sh "docker build -t test-env -f Test-env.Dockerfile ."
sh "docker build -t ${testImage} -f Test.Dockerfile ."
}
}
}
stage('Test') {
steps {
script {
def branchName = "${env.BRANCH_NAME}".toLowerCase().replaceAll("/", "_")
def dockerNet = "${branchName}-net"
def appImage = "${branchName}-app"
def testImage = "${branchName}-test"
sh "docker run -d --name ${appImage} --net ${dockerNet} ${appImage}"
sh "docker run --name ${testImage} --link ${appImage}:test-server --net ${dockerNet} ${testImage}"
}
}
}
}
post {
success {
slackSend (color: 'good', message: "SUCCESSFUL: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' (${env.BUILD_URL})", channel: "#jenkins")
}
failure {
slackSend (color: 'danger', message: "FAILED: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' (${env.BUILD_URL})", channel: "#jenkins")
}
always {
script {
def branchName = "${env.BRANCH_NAME}".toLowerCase().replaceAll("/", "_")
def dockerNet = "${branchName}-net"
def appImage = "${branchName}-app"
def testImage = "${branchName}-test"
sh "docker ps -a --filter name=${branchName} -q | xargs docker stop || true"
sh "docker ps -a --filter name=${branchName} -q | xargs docker rm || true"
sh "docker images --filter=reference='*${branchName}*:*' -q | xargs docker rmi || true"
sh "docker network ls --filter=name=${branchName}-* -q | xargs docker network rm || true"
}
cleanWs()
}
}
}