-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
97 lines (85 loc) · 2.61 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
#!/usr/bin/env groovy
def toolImage = 'node:6.10.0'
def documentationImage = 'asciidoctor/docker-asciidoctor'
def dockerRegistry = 'https://index.docker.io/v1/'
def dockerCredentialsId = 'docker-hub'
def commitId
node {
stage('prepare') {
checkout scm
commitId = getCommitId()
docker.image(toolImage).inside {
sh 'npm install'
}
stash 'workspace'
}
}
stage('run') {
parallel compilation: {
node {
unstash 'workspace'
docker.image(toolImage).inside {
sh 'npm run build'
}
stash includes: 'dist/**.*', name: 'dist'
stash includes: 'run-e2e.sh, Dockerfile', name: 'scripts'
}
}, 'unit tests': {
node {
unstash 'workspace'
docker.image(toolImage).inside {
sh 'npm run test -- --code-coverage --single-run true'
}
stash includes: 'coverage/**.*', name: 'coverage'
}
}, 'documentation': {
node {
unstash 'workspace'
docker.image(documentationImage).inside {
sh 'asciidoctor -o output/index.html doc/application.adoc'
}
stash includes: 'output/**.*', name: 'documentation'
}
}
}
node {
unstash 'dist'
unstash 'coverage'
unstash 'documentation'
unstash 'scripts'
def dockerImage
stage('build image') {
dockerImage = docker.build "pierrebtz/paris-meetup-pipeline-docker-app:${commitId}"
}
stage('e2e') {
/* in our real case, we use protractor with a selenium grid,
with parallel branches for the different browsers.
To keep the demo autocontained, the protactor test is replaced by a
simple curl call checking whether the container correctly serves a page or not.
*/
dockerImage.withRun('-P') { c ->
def containerUrl = c.port(80).replaceAll('0.0.0.0', getHostIp())
sh "./run-e2e.sh ${containerUrl}"
}
}
stage('publish') {
parallel "docker image": {
docker.withRegistry(dockerRegistry, dockerCredentialsId) {
dockerImage.push()
if ("${env.BRANCH_NAME}" == 'master') {
dockerImage.push 'latest'
}
}
}, 'code coverage': {
publishHTML([allowMissing: false, alwaysLinkToLastBuild: true, keepAll: true, reportDir: 'coverage', reportFiles: 'index.html', reportName: 'Coverage'])
}, 'documentation': {
publishHTML([allowMissing: false, alwaysLinkToLastBuild: true, keepAll: true, reportDir: 'output', reportFiles: 'index.html', reportName: 'Documentation'])
}
}
}
def getCommitId() {
sh returnStdout: true, script: 'echo -n $(git rev-parse --short HEAD)'
}
def getHostIp() {
sh returnStdout: true, script: 'echo -n $(/sbin/ip route|awk \'/default/ { print $3 }\')'
}