forked from RedHatInsights/insights-host-inventory
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
92 lines (80 loc) · 3.05 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
/*
* Requires: https://github.com/RedHatInsights/insights-pipeline-lib
*/
@Library("github.com/RedHatInsights/[email protected]") _
podLabel = UUID.randomUUID().toString()
node {
cancelPriorBuilds()
runIfMasterOrPullReq {
runStages()
}
}
def runStages() {
// Fire up a pod on openshift with containers for the DB and the app
podTemplate(label: podLabel, slaveConnectTimeout: 120, cloud: 'openshift', containers: [
containerTemplate(
name: 'jnlp',
image: 'registry.access.redhat.com/openshift3/jenkins-agent-nodejs-8-rhel7',
args: '${computer.jnlpmac} ${computer.name}',
resourceRequestCpu: '200m',
resourceLimitCpu: '500m',
resourceRequestMemory: '256Mi',
resourceLimitMemory: '650Mi'
),
containerTemplate(
name: 'python3',
image: 'python:3.6.5',
ttyEnabled: true,
command: 'cat',
resourceRequestCpu: '300m',
resourceLimitCpu: '1000m',
resourceRequestMemory: '512Mi',
resourceLimitMemory: '1Gi'
),
containerTemplate(
name: 'postgres',
image: 'postgres:9.6',
ttyEnabled: true,
envVars: [
containerEnvVar(key: 'POSTGRES_USER', value: 'insights'),
containerEnvVar(key: 'POSTGRES_PASSWORD', value: 'insights'),
containerEnvVar(key: 'POSTGRES_DB', value: 'insights'),
containerEnvVar(key: 'PGDATA', value: '/var/lib/postgresql/data/pgdata')
],
volumes: [emptyDirVolume(mountPath: '/var/lib/postgresql/data/pgdata')],
resourceRequestCpu: '200m',
resourceLimitCpu: '200m',
resourceRequestMemory: '100Mi',
resourceLimitMemory: '100Mi'
)
]) {
node(podLabel) {
container("python3") {
stage('Setting up environment') {
withStatusContext.custom('setup') {
scmVars = checkout scm
runPipenvInstall(scmVars: scmVars)
sh "${pipelineVars.userPath}/pipenv run python manage.py db upgrade"
}
}
stage('Pre-commit checks') {
withStatusContext.custom('pre-commit') {
sh "${pipelineVars.userPath}/pipenv run pre-commit run --all-files"
}
}
stage('Unit Test') {
jUnitFile = 'junit.xml'
withStatusContext.unitTest {
sh "${pipelineVars.userPath}/pipenv run python -m pytest --cov=. --junitxml=${jUnitFile} --cov-report html -sv"
}
junit jUnitFile
archiveArtifacts jUnitFile
archiveArtifacts "htmlcov/*"
}
stage('Code coverage') {
checkCoverage(threshold: 80)
}
}
}
}
}