This repository has been archived by the owner on Sep 16, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Jenkinsfile
141 lines (127 loc) · 4.41 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
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
pipeline {
agent { label "!master"} //run on slaves only
environment {
DOCKER_REGISTRY = 'registry.service.opg.digital'
IMAGE = 'opguk/lpa-pdf'
}
stages {
stage('lint') {
steps {
echo 'PHP_CodeSniffer PSR-2'
sh '''
docker run -i --rm --user `id -u` -v $(pwd):/app registry.service.opg.digital/opg-phpcs-1604 --standard=PSR2 --report=checkstyle --report-file=checkstyle.xml --runtime-set ignore_warnings_on_exit true --runtime-set ignore_errors_on_exit true src/
'''
}
post {
always {
checkstyle pattern: 'checkstyle.xml'
}
}
}
stage('unit tests') {
steps {
echo 'PHPUnit'
sh '''
docker run -i --rm --user `id -u` -v $(pwd):/app registry.service.opg.digital/opg-phpunit-1604 tests -c tests/phpunit.xml --log-junit unit_results.xml
'''
}
post {
always {
junit 'unit_results.xml'
}
}
}
stage('unit tests coverage') {
steps {
echo 'PHPUnit with coverage'
sh '''
docker run -i --rm --user `id -u` -v $(pwd):/app registry.service.opg.digital/opg-phpunit-1604 tests -c tests/phpunit.xml --coverage-clover tests/coverage/clover.xml --coverage-html tests/coverage/
echo 'Fixing coverage file paths due to running in container'
sed -i "s#<file name=\\"/app#<file name=\\"#" tests/coverage/clover.xml
'''
step([
$class: 'CloverPublisher',
cloverReportDir: 'tests/coverage',
cloverReportFileName: 'clover.xml'
])
}
}
stage('build') {
steps {
sh '''
docker-compose down
docker-compose build
'''
}
}
stage('functional tests') {
steps {
sh '''
rm -r -f test-data/output/
docker-compose run --rm --user `id -u` pdf bash -c "cd app;php tools/testAll.php"
'''
}
post {
success {
archiveArtifacts artifacts: 'test-data/output/*.pdf'
}
}
}
stage('create the tag') {
steps {
script {
if (env.BRANCH_NAME != "master") {
env.STAGEARG = "--stage ci"
} else {
// this can change to `-dev` tags we we switch over.
env.STAGEARG = "--stage master"
}
}
script {
sh '''
virtualenv venv
. venv/bin/activate
pip install git+https://github.com/ministryofjustice/[email protected]
git fetch --tags
semvertag bump patch $STAGEARG >> semvertag.txt
NEWTAG=$(cat semvertag.txt); semvertag tag ${NEWTAG}
'''
env.NEWTAG = readFile('semvertag.txt').trim()
currentBuild.description = "${IMAGE}:${NEWTAG}"
}
echo "Storing ${env.NEWTAG}"
archiveArtifacts artifacts: 'semvertag.txt'
}
}
stage('build image') {
steps {
sh '''
docker build . -t ${DOCKER_REGISTRY}/${IMAGE}:${NEWTAG}
'''
}
}
stage('push image') {
steps {
sh '''
docker push ${DOCKER_REGISTRY}/${IMAGE}:${NEWTAG}
'''
}
}
stage('trigger downstream build') {
when {
branch 'master'
}
steps {
build job: '/lpa/opg-lpa-docker/master', propagate: false, wait: false
}
}
}
post {
// Always cleanup docker containers, especially for aborted jobs.
always {
sh '''
docker-compose down --remove-orphans
'''
}
}
}