This repository has been archived by the owner on Mar 8, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathJenkinsfile-build
99 lines (93 loc) · 2.91 KB
/
Jenkinsfile-build
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
#!groovy
def dockerImage = ''
pipeline {
environment {
REGISTRY = "cmudb/performance-storage-service"
REGISTRY_CREDENTIAL = 'cmudb-dockerhub'
VERSION = "4.3.3"
TIMESCALE_IMAGE = 'timescale/timescaledb:latest-pg12'
}
agent {
label 'docker'
}
stages{
stage('Checkout'){
steps{
checkout scm
}
}
stage('Build'){
steps{
dir('performance-storage-service'){
script{
dockerImage = docker.build REGISTRY + ":${VERSION}"
}
}
}
}
stage('Test'){
steps{
script{
dir('performance-storage-service'){
docker.withRegistry('', REGISTRY_CREDENTIAL) {
sh "docker ps"
sh "mkdir reports"
docker.image(TIMESCALE_IMAGE).withRun("-e POSTGRES_PASSWORD=password -p 5432:5432 ") { ts ->
/* Wait until timescale service is up */
sh """
sudo apt-get update
sudo apt-get install postgresql-client -y
until pg_isready -d postgres -h 127.0.0.1 -p 5432 -U postgres > 1; do
echo "Waiting for postgres server"
sleep 1
done"""
dockerImage.inside("--net=host -e SECRET_KEY=shhh -e PSS_CREATOR_USER=jenkins -e PSS_CREATOR_PASSWORD=password --mount type=bind,source=${WORKSPACE}/performance-storage-service/reports,target=/performance-storage-service/reports --entrypoint=''" ){
sh 'python manage.py jenkins --enable-coverage --coverage-rcfile=.coveragerc'
}
}
}
}
}
}
post{
always{
junit "**/reports/junit.xml"
cobertura onlyStable: false, coberturaReportFile: '**/reports/coverage.xml'
recordIssues enabledForFailure: true, tool: pep8(pattern: 'performance-storage-service/reports/pep8.report'), filters: [excludeFile('.*/usr/local/lib/.*')]
recordIssues enabledForFailure: true, tool: flake8(pattern: 'performance-storage-service/reports/flake8.report'), filters: [excludeFile('.*/usr/local/lib/.*')]
}
}
}
stage('Publish'){
when{
branch 'master'
}
steps{
script{
dir('performance-storage-service'){
docker.withRegistry('', REGISTRY_CREDENTIAL) {
dockerImage.push("latest")
dockerImage.push("${VERSION}")
}
}
}
}
}
}
post {
cleanup{
script{
if (env.BRANCH_NAME == 'test') {
echo "removing docker image"
sh "docker rmi ${REGISTRY}:${VERSION}"
}
echo "stopping timescaledb if it wasn't already stopped"
sh "docker stop timescaledb || true"
echo "removing timescale image"
sh "docker rmi ${TIMESCALE_IMAGE} -f"
echo "deleting directory"
deleteDir()
}
}
}
}